After the Server Control triggers the alert dialog box on the client, the server returns the server as needed.

Source: Internet
Author: User

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

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.