5}Validation Group:-



Assume that we have two separate set of designs in the same webpage like 

Create a new webpage

Design the webpage



Set the following properties for RequiredFieldValidator2:-

ID                                  ---      RF1

ControlToValidate           ---      Enter UserName

Text                               ---      Enter Password

Set the following properties for RequiredFieldValidator2:-

ID                                  ---      RF2

ControlToValidate          ---      txtUserName

Text                               ---      Enter Password


Set the following properties for RequiredFieldValidator2:-


ID                                  ---      RF

ControlToValidate           ---      txtHTNum

Text                               ---      Enter HallTicket Number

Write the following code in Login & Submit Buttons

protected void btnLogin_Click (object sender, EventArgs e)
{
        lblDisplay.Text = "Login Successfull";
 }
 protected void btnSubmit_Click (object sender, EventArgs e)
 {
        lblDisplay.Text = "Fail";
 }


  • In the above Example when user clicks on login by entering UserId, Password.
  • It also will ask the user to enter Hall Ticket Number at the same time when user is entering Hall Ticket Number and clicks on Submit Button. It also will ask user to enter UserName and Password. But this should not happen.
  • To overcome this drawback we use “Validation Group” Property
  • when we set “Validation Group” common validations are performed  to the same group .
  • select RF1 & RF2& Login Button set Validation Group as “V1”
  • Select the Controls “RF3&Submit” Button set validation group as “V2”.
  • Now when user clicks on Login Button only “RF1 & RF2” will be executed and “RF3” will not be executed.
  • Whenever user clicks on Submit Button only “RF3” will be executed, “RF1 & “RF2” will not be executed.
  • Run the Application and Check.


No comments:

Post a Comment