4}RangeValidator:-

  • This Control is used to compare the data entered by user is within the specified Range or Not ?
  • If Data Entered by user is within specified Range then RangeValidator will return true to the Webpage otherwise will return false to the webpage.
Properties with RangeValidator:-


1)    ControlToValidate

2)    ErrorMessage

3)    Text

4)    ValidationGroup

5)    MinimumValue

6)    MaximumVallue

7)    Type(options:[String(Default/Integer/Double/Date/Currency)])

8)    CausesValidation

5)Minimum Value:-Used to set or get the least value that is to be compared with

6)Maximum Value:-used to set or get highest value up to where it is to be compared. 

Example with RangeValidator:-

 Validations to be performed:-

   Age should be from 35to 55 years only

   Create a new Webpage, Design the Webpage




Set the following properties to RangeValidator1:-

ID                                            ---                RV1

ContrrolToCompare                 ---                txtAge

Text                                         ---                Age Should be 35 to 55

MinimumValue                         ---                35

MaximumValue                         ---                55

Type                                        ---                Integer
 Write the following code in Submit Button:-

protected void btnSubmit_Click(object sender, EventArgs e)
{
        lblDisplay.Text = "Page Submitted";
}



Example for CausesValidation Propery Using 2 RequiredFieldValidators 

Create a new web page&  design the WebPage
Set the following properties for the RequiredFieldValidator:-
 
ID                                             ---                RF1

ControlToValidate                      ---                txtPassword

Text                                          ---                Enter UserName


 Set the following properties for the RequiredFieldValidator2:-

ID                                           ---      RF2

ControlToValidate                    ---      txtPassword

Text                                        ---      Enter the Password

  • create a link to other page from new user link Button(Default.aspx)
  • Write the following code in Login Button Click Event
              lblDisplay.Text=”Login Successfull”; 
Run The Application  and Check

  • If existing user clicks on LoginButtton without entering Username or Password then validation Control will work and message will be display like Enter Username, Enter Password.
  • But if a new user is coming and clicking on new UserLinkButton then also it will prompted (asked) to enter Username ,Password.
  • That means in this page when user clicked on Login Button then only validation should be performed & if user clicks on New User Link Button then validations should not be performed.
  • For this purpose we use a property with ASP.Net standard Controls i.e., Causes Validation.
  • When for any Control Causes Validation is set “True” .Then validation Controls will perform the validations otherwise when set to “False” & when user clicks on Control validation Control do not perform any validations.
  • To solve the above problem select New User Link Button
  • Go to properties set CausesValidation to False.


No comments:

Post a Comment