You have two logical sections on a form with controls that require different validation as a function of the button the user clicks, such as a form that supports login and new user registration.
For each group of controls and its associated form-submit button, set the
ValidationGroup attribute to a unique group name and set the
CausesValidatio attribute of the form-submit buttons to
In the .aspx file:
ValidationGroup attribute of a form-submit button to a unique group name.
ValidationGroup attribute of each of the controls to be validated when the button is clicked to the same group name as the form-submit button.
Set the form-submit button’s
CausesValidation attribute to True to have validation performed when the button is clicked.
Repeat steps 1–3 for each form-submit button and its associated controls.
In the code-behind class for the page, use the .NET language of your choice to add code to the event handler for each button’s click event to check the
Page.IsValid property and verify that all validation was successful. (See Recipe 3.1 for details.)
Figure 3-14 shows a typical form with normal, error-free output. Figure 3-15 shows the error message that appears on the form when a validation error occurs in the login section of the form. Figure 3-16 shows the error message that appears on the form when a validation error occurs in the form’s register section. ...