SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a visual web part that has an update panel that has a button that performs an action. I want to prevent users from hitting that button more than once.

The solutions I found use javascript to disable the button then do the postback.

The problem with this that I am having is that my buttonclick method is getting called 2 times since it seems to go to Page_Load 2 times.

Here is my code. First the button and javascript then the Page_Load method.

 <script type="text/javascript">
    function DisableButton() {
        document.getElementById('<%= BetOnCar.ClientID %>').disabled = "disabled";
        __doPostBack('<%= BetOnCar.ClientID %>', ''); 


<asp:Button ID="BetOnCar" runat="server" Text="Bet" OnClientClick="DisableButton();" onclick="BetOnCar_Click" Enabled="false" />

protected void Page_Load(object sender, EventArgs e)
        string controlName = this.Page.Request["__EVENTTARGET"];
        if (BetOnCar.ClientID == this.Page.Request["__EVENTTARGET"])
            BetOnCar_Click(sender, e);

I'm hoping that I am doing this type of thing in the wrong location because it seems like page_load gets hit more often than I expected.

share|improve this question
Does this actually find your button: document.getElementById('<%= BetOnCar.ClientID %>') – Christophe Sep 7 '12 at 17:41
It does get the button. – Josh Sep 7 '12 at 18:27

I think you have add return false; in the javascript function DisableButton() OR use Jquery event.preventDefault() .

As the default button click is also firing

share|improve this answer

You'll get two post backs since you're adding a __doPostBack() in your DisableButton() function. Try to remove that one.

share|improve this answer
I tried that and I get only one postback but there is no way to know what to call from this as this.Page.Request["__EVENTTARGET"] is "" and it still won't directly go to the button click method – Josh Sep 7 '12 at 18:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.