TextBoxX Primer

After implementing separate TextBox and Validator controls over and over again, we thought it would be nice to add one TextBox control to the page, set a few properties, and have it know how to validate things for us. So this is what we did with TextBoxX.

Specifications

Inherits System.Web.Ui.WebControls.TextBox (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox(VS.80).aspx)

Properties

Property Type Default Value Notes
CustomRegularExpression String None A regular expression input should be tested against.
DataType String Value will cause input to be validated against a specific data type. Options are:

  • DateTime
  • Decimal
  • Integer
  • String
DataSubType None Value will cause input to be in a certain format. Options are:

  • Email
  • CustomRegex
ErrorIndicator String None Value will be shown next to textbox when an error occurs
ErrorMessageRequired String FieldName & ” is required.” Custom error message to be displayed with required validation fails
ErrorMessageInalid String FieldName & ” is not valid.” Custom error message to be displayed when data type validation fails
FieldName String Control’s ID The name of the field to be used in error messages when detailed message strings are not provided
IsRequired Boolean False If set to true, will require some input.
MaxLength Integer None If provided, String value must not be longer than specified or Invalid error message will be displayed.
MinLength Integer None If provided, String value must be at lease length specified or Invalid error message will be displayed.
Precision Integer 12 Number of digits allowed to the left of the decimal place
Scale Integer 3 Number of digits allowed to the right of the decimal place

Example 1: Text Box with Default Error Message in Summary and * next to field in error

<asp:TextBoxX id="txtAppGroupName" runat="server" IsRequired="true" MaxLength="200" Width="250" FieldName="Group Name" ErrorIndicator="*" />
 

Validator 1

Example2: Text Box with Developer-defined Message in Summary and * next to field in error

<asp:TextBoxX id="txtAppGroupName" runat="server" IsRequired="true" MaxLength="200" Width="250" FieldName="Group Name" ErrorMessageRequired="Please enter a Group Name" ErrorIndicator="*" />
 

Validator 2

Example 3: Text Box with Default Error Message and No Error Indicator

<asp:TextBoxX id="txtAppGroupName" runat="server" IsRequired="true" MaxLength="200" Width="250" FieldName="Group Name" />
 

Validator 3

Additional Usage examples will be tagged in our weblog as TextBoxX

Share It:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • E-mail this story to a friend!
  • Netvibes
  • Ping.fm
  • Reddit
  • StumbleUpon
  • Technorati