This Control is used to check whether user entered data is within
the required format or not like EmailId format, Web Address format, Pin
code Format, Phone Number Format etc.
Properties
with RequiredFieldValidator
:-
1. ControlToValidate2. ErrorMessage3. Text4. ValidationGroup5. Validation Expression
Example with RegularExpreessionValidator:-
- Create a new webpage
- Design the webpage
Select
the RegularExpressionValidator and
set the following Properties:-
(ID) --- RE1ControlToValidate --- txtEmailIdText --- Invalid MailIdFormat
ValidationExpresssion
- Click on Ellipses Button
- Select Internet Email Address
- Click on Ok
Write
the following code for Submit Button
protected void btnSubmit_Click(object sender,EventArgs e){lblDisplay.Text = "Page Submitted";}
- Run the Application & Check
- In the above Example if user is not entering EmailId& Click on Submit Button then page result will be submitted to the server
- This is because Except RequiredFieldValidator no other Control capable of checking the Emptiness of the Control.
- All other validation Controls will perform the validation if there is data available in the Control only to overcome this drawback we should also use RequiredFieldValidator like:
[Add RequiredFieldValidator to the above webpage]
Set the following properties for RequireFieldValidator1:-
ID --- RF1ControlToValidate --- txtEmailIdText --- Enter EmilId
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
No comments:
Post a Comment