Typically, ASP. NET server control is triggered, even if you use JS to raise the alert dialog box, confirming the Alert dialog box will also cause a postback
This article tells how to click the Server button control, which triggers the client alert, and then sends the information back if the condition is met. This is the form authentication method to verify the identity of the user, about the form certification case process, I will open a separate blog to explain.
Step one, server background Page_Load events
public int isloginuser; protected void Page_Load (object sender, EventArgs e) { if (User.Identity.Name.Equals ("")) { Isloginuser = 0; } else { isloginuser = 1; } }
Step two, Server button control
<asp:button id= "btnsubmit" class= "btn-white button" runat= "server" text= "commit" height= "30px" OnClientClick = "if (ValidUser ()) {return true;} Else{return false} "onclick=" btnSubmit_Click "/>
Step three, client JS script
function ValidUser () { var isloginuser=<%=isloginuser%>; if (isloginuser==0) { alert ("Please login First"); return false; } else { alert ("Login user"); return true; } }
Of course, this effect can also be done using jquery asynchronous transmission, you can refer to http://blog.csdn.net/goodshot/article/details/8652171
server controls post the Alert dialog box after the client triggers the postback server operation as appropriate