16 February 2014

Range Validator-Validation Controls

  The Range Validator does exactly what the name implies; it makes sure that the user input is within a specified range. You can use it to validate both numbers, strings and dates.


Range Validator Syntax

       In this we are validating the date between two date ranges which is given as minimum value and maximum value

Date:<br />
<asp:TextBox runat="server" id="txtDate" />
<asp:RangeValidator runat="server" id="rngDate" controltovalidate="txtDate" type="Date" minimumvalue="01-01-2006" maximumvalue="31-12-2006" errormessage="Please enter a valid date within 2006!" />
<br /><br />

      In the Code Behind file, we add the following event handler:

      Protected void btnSubmitForm_Click (object sender, EventArgs e)
      {
         if(Page.IsValid)
        {
           btnSubmitForm.Text = "My form is valid!";
         }
      }

     We check whether or not the page is valid, before we do anything.

No comments:

Post a Comment