So back when I started teaching myself C# and .Net 1.0, I started learning about User Controls and how much cooler they are than include files in ASP Classic. I also had a desire to create a control that I could drop on the page, but would be like a vamped up text box. Then I started learning about Custom Controls.
So I wrote a .cs file that extended the TextBox control, added some functionality that tied into JavaScript and auto formatted text the user typed in based on a mask attribute added to the text box.
So <uc:mytextbox runat="server" id="txtPhone" mask="999-999-9999" /> would render as a standard <input /> box, but with some JavaScript it would only allow the user to type in numbers, and as they type, it would add the dashes and format the input to look like a phone number. Granted, it all relied on JavaScript on the browser, but it was pretty fun and a good learning experience.
Well, yesterday at work we had an Autonomy day. Basically a single day a quarter where we can work on or do anything we want. Either client related, or not, project related, or not. Since we have a common library what we use in all of our projects, and I like to use ASP Validator controls, I decided to create my own Custom Control which extended BaseValidator. I was able to use to validation that's already built into the common library for things like phone number, zip code and email validation through regular expressions. Having some extra time I figured out how to include some JavaScript for client side validation as well (also using the same regular expressions).
Having no idea what I was doing, and using a little bit of Google for reference, I manage to get it figured out. It was a cool exercise, I feel like I learned something, I created something that can be used by the company going forward, and also provided a platform that we can expand on the validation, as well as open the door for the other developers to see and grow their own controls as well.
All in all, I think it was a good day.
No comments:
Post a Comment