After the Server Control triggers the alert dialog box on the client, the server returns the server as needed.
Usually, after the ASP. NET Server Control is triggered, even if the alert dialog box is triggered by js, confirmation of the alert dialog box will also cause sending back.
This article describes how to click the server button control and send the message back only when the alert client is triggered. This article uses form authentication to verify the user's identity. I will open a separate blog to explain the process of form authentication.
Step 1. Server background Page_Load event
public int isLoginUser; protected void Page_Load(object sender, EventArgs e) { if (User.Identity.Name.Equals("")) { isLoginUser = 0; } else { isLoginUser = 1; } }
Step 2. Server button control
<Asp: button ID = "btnSubmit" class = "btn-white button" runat = "server" Text = "Submit" Height = "30px" OnClientClick = "if (validUser ()) {return true;} else {return false} "onclick =" btnSubmit_Click "/>
Step 3. Client js script
Function validUser () {var isLoginUser = <% = isLoginUser %>; if (isLoginUser = 0) {alert ("Please log in first"); return false ;} else {alert ("Login User"); return true ;}}
Of course, this effect can also be completed using jquery asynchronous transmission, you can refer to http://blog.csdn.net/goodshot/article/details/8652171