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