ASP.NET 2.0 Button One Click

Posted on 2006-05-15
Last Modified: 2008-06-02
Ok, so this was an issue in 1.1 but I could always do a work around using this.Page.GetPostBackEventReference(this) to force the post and some javascript. Now with 2.0 I can't seem to get it to work. Anyone got a good solution for 2.0 that allows a button/image button to be clicked only once?
You can't set it to disabled=true because then the server side will presume it is disabled. And the data won't be posted correctly.
I can't figure out where the WebForm_DoPostBackWithOptions is done, any ideas on that one as well?
ok, if anyone knows or has the server control that will work for either imagebutton or button for this I appreciate it.
Question by:jj819430
    LVL 6

    Accepted Solution

    I used to use this approach:

    <asp:Button ID="btn" onClick="ServerMethod()" onClientClick="this.enabled=false;" Text="Click Once!" />

    for better work, put the enable=false into a javascript function and then you can use it for more..
    LVL 7

    Author Comment

    this still gives the same issue.... the button doesn't post back once.
    LVL 7

    Author Comment

    nvm solved it myself.
    Basically created a server control that writes out 2 divs, 1) = the button or image button, 1 = the stuff to show while the backend is processing.
    wrap the onclick event of the button/imagebutton with the following javascript code at the pre-render state
    if(Page_ClientValidate( TheValidationGroupName )){ myScript; TheOriginalOnClick;}

    the I created a small javascript framework that gets called and swaps out the display property of the divs.

    Credit for where I started goes to Mike Ellision

    You will want to re-write a bunch of it but it is a great way to start to solve this problem. Today mike is my hero

    But remember to update the system to work in 2.0 correctly and support groupvalidations


    Expert Comment


    I'm looking for the same functionality for my image button. Can I get a copy of your button? Many thanks

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    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

    18 Experts available now in Live!

    Get 1:1 Help Now