My Software Notes

Useful things I discover

Postback after disabling a button (ASP.NET)

with 2 comments

I’ve seen it on tons of sites.  You click the button, it becomes disabled and the page posts.  The disabling is so you don’t go clicking it multiple times while waiting for the server processing to complete.  

It’s all over the place, so it must be simple right?

Well, actually, once you find out how to do it, yes it is simple, but getting there?  What a pain.

I foolishly thought I could just add another even handler for the button click using jQuery. Nope.  Although jQuery adds the event handler rather than replacing existing event handlers, the action of disabling the button seems to kill the ASP.NET postback script.

Well, of course, I should be using the “OnClientClick” property of the asp:Button control.  No problem.  Nope.  That doesn’t work either.  It overwrites the ASP.NET postback script. 

This is ridiculous.  So it’s time to start asking Google.  The first few results tell me to add the ASP.NET postback script in server code and other real complex solutions.  These just seemed way too complex to me.  I have a rule of thumb that I follow at times like this: “If it’s getting more complex you’re going in the wrong direction.”

So I hunted some more and sure enough here is the simple answer: Disable a button control during postback.

Totally simple but what a pain to discover.


Written by gsdwriter

September 9, 2010 at 9:39 am

Posted in Uncategorized

2 Responses

Subscribe to comments with RSS.

  1. Greate pieces. Keep writing such kind of information on your site.

    Im really impressed by your blog.
    Hi there, You have done a great job. I’ll certainly digg it and in my view suggest to my friends. I am sure they will be benefited from this site.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: