When there is "Button1.Attributes.Add" ("onclick", "return confirm (' Are you sure you want to save the changes?") ')");” , the workaround to verify that the control is invalidated

Source: Internet
Author: User

Same page with JS and server validation control OnClientClick submit issue

Implementation features:

Clicking the button's OnClientClick event does not affect validation of the server validation control
(The server page is not submitted if the validation does not pass)
Background:
1. There is a server validation control (RegularExpressionValidator) on the same page, multiple
2 a JavaScript function for validation and other functions
3. Button buttons, two events Onclick,onclientclick
Method:

HTML page


Validation controls:

<asp:textbox id= "txt_test" runat= "Server" width= "120px" maxlength= "8" ></asp:TextBox>
<asp:regularexpressionvalidator id= "validator_test" runat= "Server" controltovalidate= "Txt_Test"
Errormessage= "digital" validationexpression= "^/d+$" ></asp:RegularExpressionValidator>

Button:

<asp:imagebutton id= "Btnputin" runat= "Server" text= "Submit" onclick= "Btnputin_click"
Onclientclick= "if (Checkclientvalidate ()) {return checknullvalue ()}" imageurl= ": /images/submit1.gif "/>

Script:

<script type= "Text/javascript" >

Returns whether the server verifies that the control succeeded
Author:add by Aprillee at 2007-12-27
Example:onclientclick= "if (Checkclientvalidate ()) {return checknullvalue ()}"
function Checkclientvalidate ()

{
Page_clientvalidate ();

if (page_isvalid)

{
return true;

}

Else

{
return false;
}
}
The following is a custom scripting feature
function Checknullvalue ()
{
Alert (' Test ');
}
</script>

---------------------This article from Shfongfeng csdn blog, full-text address please click: 5985600?utm_source=copy

When there is "Button1.Attributes.Add" ("onclick", "return confirm (' Are you sure you want to save the changes?") ')");” , the workaround for validating control invalidation is

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.