1}RequiredFieldValidator:-

  • This Control is used to check the Emptiness of the Control i.e., to check whether user entered data or not.
  • If user entered data in the Control is to be validated then RequiredFieldValidator will return “True” to the webpage .otherwise will return “False” to the webpage.
Properties with RequiredFieldValidator :-

1.     ControlToValidate
2.     ErrorMessage
3.     Text
4.     ValidationGroup

1)ControlToValidate:-This property is used to set or gets the name of the Control that is to be validated.

2)ErrorMessage:-used to set or get the required message value that is to be displayed to the user within the validationSummary Control .if validation Control returns false.

3)Text:-Used to set or get required message that is to be displayed to the user within validation Control if validation Control return false.

4)ValidationGroup:-used to set or get a common group name for two or more Controls so that common validation can be performed for the group of Controls.

Example with RequiredFieldValidator

  • Validations to be performed:-
  • Check whether user entered Username or not
  • Username is mandatory..
  • Create a New webpage

Design the webpage [Click On Table  Menu---Select the InsertTable  option ---A  InsertTable window will open ---In this window Enter Rows:2;Columns:3;Align:Centre   ;pixels :50 --- Click on Ok
  • Go to Toolbox Select TextBox,Lable ,Button;ReqiredFieldValidator:
        Set the Properties for TextBox & Lable Button :-
               
            TextBox1   =           (ID)    ---      txtUName

             Lable1       =          (ID)     ---      lblDisplay
                                                                                                    
             Button1     =            (ID)   ---      btnSubmit
        Select RequiredFieldValidator1 set the following properties:-

             1](ID)                                       ---      RF1

             2]ControlToValidate     ---      txtUName

             3]Text                               ---   Enter UserName


     Write the following code for the submit Button

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

  • Run the Application & Check

No comments:

Post a Comment