Posted on 2011-10-14
Last Modified: 2012-05-12
hey guys i have an asp button and two click method


i want to excute the OnClick first than OnClientClick but i do not know how to?

<asp:Button ID="btnAdd" runat="server" CssClass="button" Text="Add" ValidationGroup="a"
                            Width="90px" OnClick="btnAdd_Click"  />

see i have valiadators in my web page and when i click the button it goes into the OnClientClick method which is wrong.

it for to valiadate the page then move to OnClientClick method.

please help?
Question by:JCWEBHOST
    LVL 22

    Expert Comment

    by:Ivo Stoykov
    you cannot because first into events chain comes ClientClick...


    Ivo Stoykov
    LVL 12

    Accepted Solution


    If you want to call some javascript function after the event btnAdd_Click, add below code in last line of btnAdd_Click event.

    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "spt", "<script type=\"text/javascript\"> JScriptFunctionName(); </script>");

    Open in new window


    Author Comment

    protected void btnAdd_Click(object sender, EventArgs e)
            ScriptManager.RegisterStartupScript(this, this.GetType(), "OnClientClick", "mainScreen.ShowConfirm(this,'Please confirm','Are you sure to add customers details?');", true);
            txtcellnumber.Text = "########";

    Open in new window

    Guys this works and my javascript fires, how do i check if the uses click yes or no?

    its hard to explain this, that onclick method display a message using ModalPopupExtender with a yes and no button.

    my question is that my code on the above excutes

    txtcellnumber.Text = "########";

    before the user select yes or no.

    if they a way that ScriptManager return a value to see if the user selects the yes button

    Author Closing Comment


    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now