server controls post the Alert dialog box after the client triggers the postback server operation as appropriate

Source: Internet
Author: User

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

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.