Home > Net >  Onclientclick entanglements with onclick (onclientclick don't affect other button?)
Onclientclick entanglements with onclick (onclientclick don't affect other button?)

Time:01-09

Today met a very magical phenomenon, there is a button it
 & lt; Cc7: commonbutton runat="server" id="btnLogin text"="login" 
Onclientclick="ValidateAndConfirm (); Return false;" Validationgroup="vgSearch" onclick="btnLogin_Click"/& gt;

Js is written so
 function ValidateAndConfirm () {
SetTimeout (function () {
Page_ClientValidate ();
if (! Page_IsValid) {
ShowMsgBox1 (" error ");
return;
}
ShowMsgBox2 (" sure to continue? ");
}, 0);
}


The button itself without any problems, if you have any what must value without picture will enter ShowMsgBox1, if in a full range of values will enter ShowMsgBox2, choose OK to go to the service side btnLogin_Click method,
Then came the question that exist under him another button
 & lt; Cc7: commonbutton runat="server" id="btnClearDetail text"="empty" onclick="btnClearDetail_Click"/& gt; 


once the error log in button to enter ShowMsgBox1 (" error "); , press delete button no response for the first time, according to the second will perform the onclick,
1 experiment: inside the delete button for onclientclick event is executed, then the delete button add onclientclick="return true;" But onclick won't execute
Experimental 2 : will onclientclick="ValidateAndConfirm (); Return false;" return false. deleted, enter ShowMsgBox1 , empty press will be carried out for the first time, but to enter ShowMsgBox2 , a flash picture about small window, direct execution of landing button onclick ,
Experimental 3 : will Page_ClientValidate (); delete, empty press will perform for the first time, but the Page_IsValid true lead to go into the ShowMsgBox2 not ShowMsgBox1
Experimental 4 : will ValidateAndConfirm way to write into the background CS btnLogin. Attributes. Add (" onclick ", "javascript: ValidateAndConfirm (); Return false;" ); , there is no any difference in results and the start,
Is there anyone know why great god, or also encountered the same situation,

CodePudding user response:

 
The function ValidateAndConfirm () {
SetTimeout (function () {
Page_ClientValidate ();
if (! Page_IsValid) {
ShowMsgBox1 (" error ");
return false;
}

ShowMsgBox2 (" sure to continue? ");
return true;
}, 0);
}


Then onclientclick="ValidateAndConfirm ()" try
  • Related