ASP. NET 2.0 resolves the conflict between the Button and the verification control: ValidationGroup

Source: Internet
Author: User

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:

 
 
  1. <Asp: TextBox ID ="TxtOldPs"Runat ="Server"Width ="150px"> </Asp: TextBox>
  2. <Asp: RequiredFieldValidator ID ="RequiredFieldValidator1"Runat ="Server"ControlToValidate ="TxtOldPs" 
  3. Display ="None"ErrorMessage ="<B> reminder </B> <br/> enter the original password !! "ValidationGroup ="Valibench roup1"> </Asp: RequiredFieldValidator>

Button event:

 
 
  1. <Asp: Button ID ="ButtonOK"Runat ="Server"Text ="Modify"OnClick ="Edit_Click"ValidationGroup ="Valibench roup1"/>

You do not need to set ValidationGroup for another button.

 
 
  1. <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.

  1. Application of session storage mode in ASP. NET
  2. Set of methods for uploading and downloading files in ASP. NET
  3. Introduction to cookie read/write methods in ASP. NET
  4. Javascript operations in ASP. NET
  5. Introduction and implementation of Single Sign-On in ASP. NET2.0

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.