ASP. NET multiple button events on a page to avoid data verification control requiredfieldvalidator conflict

Source: Internet
Author: User

Link: http://www.cnblogs.com/hakuci/archive/2008/08/01/1153007.html

 

Problem description: create multiple buttons on a page. By default, the button event conflicts with the data verification control: when one of the buttons is clicked, you want a specific validator to be fired, instead of all validator on the page. Validator is not required for other buttons. The data verification control is enabled.

Note: There is no better way except the hack code in ASP. NET 1.1. In ASP. NET 2.0, the validator group attribute is added to all validator controls and buttons (such as buttons and linkbuttons) to easily solve this problem. 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 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 = "validatagroup1"> </ASP: requiredfieldvalidator>

Button event:
<Asp: button id = "buttonok" runat = "server" text = "modify" onclick = "edit_click"Validationgroup = "validatagroup1"/>

You do not need to set another buttonValidationgroup
<Asp: button id = "buttonok" runat = "server" text = "quit" onclick = "exit_click"/>

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.