Properties
with CompareValidator:-
1) ControlToValidate2) ErrorMessage3) Text4) ValidationGroup5) ControlToCompare6) Operator(options[Equal(Default)/LessThan/LesThanEqual/GreaterThanEqual/GreterThan/NotEqual/DataTypeCheck])7) ValueToCompare
8) Type(options[String(Default)/Integer/Double/Date/Currency])
5)ControlToCompare:-Used to set or get the Id of the Control with which we want to compare6) Operator:-Used to set or get the required operator value that is to be compared with.7) ValueToCompare:-Used to set or get a fixed value with which the user entered data we want to compare.8) Type:-Used to set (or) get the required data type value that is to comparedIf the data entered by user in the Control to validate matches with the data entered in ControlToCompare or value to compare then CompareValidator will return true to the Webpage otherwise CompareValidator will return False to the Webpage.
Example with CompareValidator:-
Create
a new webpage
Design
the webpage
- To compare txtReTypePassword data with txtPassword data set the following properties
ID --- CV1ControlToCompare --- txtPasswordControlToValidate --- txtReTypePasswordText --- Password Do not MatchOperator --- EqualType --- String
Write the following code for submit Button:-
protected void
btnSubmit_Click (object sender, EventArgs e)
{
lblDisplay.Text = "Page Submitted to the Server";
}
|
- Run the WebPage & Check
Validations to be
performed:
Age
>35 years.
Create
a new webpage, design the webpage
Set the following
properties for CompareValidator1:-
ControlToValidate --- txtAgeValueToCompare --- 35Operator --- GreaterThanEqualType --- IntegerText --- Enter age >=35
Write the following code in Submit Button
protected void
btnSubmit_Click(object sender, EventArgs e)
{
lblDisplay.Text = "Page Submitted";
}
|
Run
the WebPage & Check
validations to be performed
txtAge should Accept Digits only
Create a new webpage
Design the webpage
Set the following
properties for CompareeValidator1
ID --- CV1ControlToValidate --- txtAgeOperator --- DataTypeCheckType --- IntegerText --- Enter Digits only
Write the following code in Submit Button
protected void
btnSubmit_Click(object sender, EventArgs e)
{
lblDisplay.Text = "Page Submitted";
}
|
- Run the Application & Check
No comments:
Post a Comment