Problem description: create multiple buttons on a page. By default, the Button conflicts with the verification control: when one of the buttons is clicked, you want a specific validator to be fired instead of all validator in the page (such as verifying whether the user name is available ). Validator is not required for other buttons. The data verification control is enabled.
Note: In asp.net 1.1, there is no better solution except the hack code to the conflict between the Button and the verification control. In asp.net 2.0, the ValidatorGroup attribute is added to all verification controls and buttons (such as buttons and linkbuttons) to solve this problem easily. If there is a TextBox in the page and there is a RequiredFieldValidator and Button control next to it, you can set the ValidationGroup attributes of RequiredFieldValidator and Button to the same value so that only the validator of RequiredFieldValidator is triggered when you click the button. Any other validator that is not defined in the ValidationGroup will be ignored.
Example:
Text Box and data verification controls:
- <Asp: TextBox ID ="TxtOldPs"Runat ="Server"Width ="150px"> </Asp: TextBox>
- <Asp: RequiredFieldValidator ID ="RequiredFieldValidator1"Runat ="Server"ControlToValidate ="TxtOldPs"
- Display ="None"ErrorMessage ="<B> reminder </B> <br/> enter the original password !! "ValidationGroup ="Valibench roup1"> </Asp: RequiredFieldValidator>
Button event:
- <Asp: Button ID ="ButtonOK"Runat ="Server"Text ="Modify"OnClick ="Edit_Click"ValidationGroup ="Valibench roup1"/>
You do not need to set ValidationGroup for another button.
- <Asp: Button ID ="ButtonOK"Runat ="Server"Text ="Exit"OnClick ="Exit_Click"/>
In this way, the ValidationGroup solves the conflict between the Button and the verification control.
- Application of session storage mode in ASP. NET
- Set of methods for uploading and downloading files in ASP. NET
- Introduction to cookie read/write methods in ASP. NET
- Javascript operations in ASP. NET
- Introduction and implementation of Single Sign-On in ASP. NET2.0