ASP. NET multiple button events on a page prevent data verification controls from conflicting with requiredfieldvalidator

Source: Internet
Author: User
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. ASP. NET
In 2.0, the validator group attribute is added to all validator controls and buttons (buttons, linkbuttons, and so on) to easily solve this problem.
Problems. If there is a textbox in the page and there is a requiredfieldvalidator next to it
And the button control, you can set the validationgroup attribute of requiredfieldvalidator and button to the same value, so that the point
When you click a button, only the valider of requiredfieldvalidator is triggered.
Validator is 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.