TextBoxLengthValidator Demo

This demo illustrates use of the TextBoxLengthValidator validation control. The first TextBox cannot exceed 50 characters; the second cannot exceed 500 characters. Try it out!


What is your name?    

Tell us about yourself:
 


Source Code
<%@ Register TagPrefix="cc1" Namespace="skmExtendedValidators" Assembly="skmExtendedValidators" %>

<script runat="server" language="C#">

  void SubmitForm(object sender, EventArgs e)
  {
    if (Page.IsValid)
      Response.Write("Data is valid!");
    else
      Response.Write("<font color=\"red\">There is invalid data here!</font>");
  }

</script>


<form id="Form1" method="post" runat="server">
	<P>What is your name?
		<asp:TextBox id="name" runat="server" Text="Oh my, this input here is already too long!  In fact, if you try to submit the form right now you should get an error."></asp:TextBox> 
		<cc1:TextBoxLengthValidator MaximumLength="50" id="TextBoxLengthValidator1" runat="server" ErrorMessage="Name may not exceed 50 characters in length."
			ControlToValidate="name"></cc1:TextBoxLengthValidator></P>
	<P>Tell us about yourself:<BR>
		<asp:TextBox id="aboutYou" runat="server" TextMode="MultiLine" Columns="40" Rows="6"></asp:TextBox>
		<cc1:TextBoxLengthValidator id="TextBoxLengthValidator2" runat="server" ErrorMessage="Please limit your entry to 500 characters."
			ControlToValidate="aboutYou" MaximumLength="500"></cc1:TextBoxLengthValidator></P>
	<P>
		<asp:Button id="Button1" runat="server" Text="Save Information" OnClick="SubmitForm"></asp:Button></P>
</form>	
	


[Return to the article...]