ASP.NET Postback Control Lost When Button is Disabled via JavaScript

You know those bugs that frustrate you to no end, resulting in some screaming, hair-pulling, etc? I had one of those a few days ago. For some reason data on the form I was working on stopped saving. I had no idea why. The code was all there. The server-side code hadn’t changed. I checked and re-checked everything (so I thought). I even deleted the aspx and aspx.vb files and recreated them. Finally I realized that for some reason my client-side disabling of a button after-click was doing some weird things on poastback.

Here’s what I figured out. On my site, I want to disable a button once it is clicked to prevent multiple posts. So I disable the button on the click utilizing jQuery. However when I do this, the postback occurs but the control that triggered the postback is lost on the server. The server-side code handling that button click does not fire at all. When I check Page.IsPostBackEventControlRegistered, it returns false.

When I attempt to just hide the control on click, the postback details are not lost. However, I would prefer not to do this since it results in layout jitter. Adding in a faux-button span or something like that is possible, but a bit hokey. Disabling the button on click is the most straightforward method to prevent multiple postbacks from the client. I haven’t checked if this issue is caused by jQuery though I doubt it, and think that simply disabling the button in JavaScript is the issue.

Anyone have a similar issue with button disabling?

Advertisement

No comments yet

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Follow

Get every new post delivered to your Inbox.