SgDotNet
Singapore Professional .NET User Group -For Cool Developers

[SG] ValidTextBox server control for VS 2005

rated by 0 users
This post has 0 Replies | 0 Followers

Top 50 Contributor
Posts 47
alvinz_c Posted: 11-17-2006 12:15 AM

 

ASP.NET Web developers, are you tired dragging and dropping validator controls to the textbox that needs to have validation against user inputs on Web. It might be said time and effort-consuming to have validation checking in textboxes using ASP.NET 's shipped-in validator controls like RequiredFieldValidator and RegularExpressionValidator controls. IF you have 10 textboxes needs to be validated, you need to drag the validator controls at least 10 times (more than that if you use combination of both validators) from the toolbox.

I have developed a custom textbox server control, namely ValidTextBox that integrates validator controls (RegularExpressionValidator and RequiredFieldValidator) and normal textbox control during my weekend before Raya comes. It basically reduces the developers' validation checking effort in their development.

 

Figure 1 .  You just need to drag one ValidTextBox server control instead of 3 server controls.

 

Basic Validation Types
The ValidTextBox server control has 14  basic types of validation :

  1. Address
  2. Alphabet
  3. Alphanumeric
  4. Date
  5. Decimal / Price
  6. Email
  7. Singaporean NRIC No.
  8. Singaporean Phone No.
  9. Singaporean Mobile Phone No.
  10. Name
  11. Numeric
  12. Password Complexity (Check whether password entered is strong)
  13. Singaporean Postal Code
  14. Web URL
  15. Custom (Expression defined by developers)

Figure 2 - Properties of ValidTextBox server control. 

 

The ValidTextBox server control also exposes ErrorImageUrl property, which allows the developers to show an error image instead of text message when control is invalid.

 


When the ErrorImageUrl property is specified, the text in ErrorMessage property will be displayed as tooltip of the image shown. On the other hand, the ErrorMessage property will be shown if ErrorImageUrl property is empty (unspecified).

 

Flexibility of ValidTextBox Control
1. Developers can freely define their own regular expression (CustomExpression property) for their own specific user input validation.
2. Exposes common properties of validator control (eg. EnableClientScript, FontColor, ErrorMessage, CssClass), though not all of them.
3. Each validation has default error message to be displayed. You can override the default one with your own custom error message.
4. Similarly to the normal textbox server control, ValidTextBox server control inherits all of the properties of the <asp:TextBox server control.
5. Properties can be either set programmatically, declaractively or at design-time.

<lvwc:ValidTextBox ID="ValidTextBox1"runat="server" AllowEmpty="False">
     <
RegExField ValidationType="Email" ErrorMessage="Invalid email address, brother!" CssClass="" CustomExpression=""></RegExField>
     <
RequiredField ErrorMessage="**" CssClass=""></RequiredField>
</
lvwc:ValidTextBox>

or

<lvwc:ValidTextBox ID="ValidTextBox1"
  
RequiredField-ErrorMessage="**" RequiredField-CssClass=""
  
RegExField-ValidationType="Email" RegExField-CssClass="" RegExField-CustomExpression=""
  
runat="server" AllowEmpty="False">
</
lvwc:ValidTextBox>



Downloads

ValidTextBox Server Control (dll)   (Documentation will be uploaded once completed)

(You also can download the ValidTextBox server control, specially for Malaysia context here)

 

Hope this control helps...

- Alvin Chooi, Malaysia - Microsoft ASP.NET™ Enthusiast - URL: http://forums.asp.net Blog: http://alvinzc.blogspot.com
Page 1 of 1 (1 items) | RSS
Copyright SgDotNet 2004-2008
Powered by Community Server (Commercial Edition), by Telligent Systems