Onlineatoz.net | All posts tagged 'validation control'

ToolBox Validation Control RangeValidator

RangeValidator Web Server Control

in ASP.NET environment,This article describes you how to work with RangeValidator Web Control.This control can be used to ensure the entered values within a desired range menas that Checks that a user's entry is between specified lower and upper boundaries. You can check ranges within pairs of numbers, alphabetic characters, and dates.

The RangeValidator control uses four key properties to perform its validation. The ControlToValidate property contains the input control to validate. The MinimumValue and MaximumValue properties specify the minimum and maximum values of the valid range. The BaseCompareValidator.Type property is used to specify the data type of the values to compare. The values to compare are converted to this data type before the validation operation is performed.

The following data types that can be compared.

  • String
  • Integer
  • Double
  • Date
  • Currency

The following code snippets explains you the RequiredFieldValidator

<asp:RangeValidator id="Range1"
ControlToValidate="txt1"
MinimumValue="10"
MaximumValue="100"
Type="Integer"
EnableClientScript="false"
Text="The value from 10 to 100!"
runat="server"/>
                  
 
Formating the RangeValidator

ASP.NET validation controls allows you to customizing the format—font, size, and so on—of error text, or you can substitute a marker for error text. For example, you can have the validation control display an asterisk (*) when an error occurs.

You can also include a detailed error message in the ErrorMessage property of the validation control and add a ValidationSummary control to the page. The detailed ErrorMessage property text will appear on the page in the location of the ValidationSummary control.

To format error messages, specify the following properties,
  • ForeColor - The color of the error message text.
  • BackColor -The color behind the text.
  • Font -The font face, size, weight, and so on.
  • BorderWidth, BorderColor, and BorderStyle -The size and color of a border around the error message.

The following example demonstrates how to use the RequiredFieldValidator control to make sure that the user enters a value into the text box.

in .aspx.cs page,

void ButtonClick(Object sender, EventArgs e)
      {
         if (Page.IsValid)
         {
            Label1.Text="value in range";
         }
         else
         {
            Label1.Text="value in not range!";
         }
      }
        

in .aspx page,

<form id="Form2" runat="server">
    <h3>
        RangeValidator Example</h3>
    Enter a number from 1 to 10:
    <br>
    <asp:TextBox ID="txt1" runat="server" />
    <br>
    <asp:RangeValidator ID="Range1" ControlToValidate="txt1"
 MinimumValue="10" MaximumValue="100"
        Type="Integer" EnableClientScript="false" Text="The value from
 10 to 100!"
        runat="server" />
    <br>
    <br>
    <asp:Label ID="Label1" runat="server" />
    <br>
    <br>
    <asp:Button ID="Button1" Text="Submit" OnClick="ButtonClick" 
runat="server" />
</form>
     
 
Related Links

Posted by: Admin
Posted on: 9/14/2009 at 5:20 PM
Tags: , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (35) | Post RSSRSS comment feed