Jason Whitehorn

MarshalByRefObject.net
posts - 48, comments - 26, trackbacks - 6

My Links

News

Archives

Post Categories

.NET

Java

Proud Member Of...

XNA

Disabling buttons on click in ASP.NET

UPDATE (12/17/2007): My blog has moved. This post is now located at: http://jason.whitehorn.ws/2006/06/18/Disabling-Buttons-On-Click-In-ASPNET.aspx




We have all seen the websites that disable "submit" buttons when you click on them. This is often done to prevent users from clicking the button multiple times.
Normally this is accomplished using an 'onclick' JavaScript event to disable the button. In ASP.NET, each server side item already has a onclick event handler which calls the server back for event processing.
To accomplish the same thing in ASP.NET, you could easily do:

btnSubmit.Attributes.Add("onclick", "this.disabled=true;" + GetPostBackEventReference(btnSubmit).ToString());


Where 'btnSubmit' is the name of the button in question. What happens here is we create an onclick event that does two things. Firstly, it disables the button in the users browser. The second thing it does is submit the normal postback event to the server.

Print | posted on Saturday, June 17, 2006 8:16 PM | Filed Under [ .NET ASP.NET ]

Feedback

Gravatar

# re: Disabling buttons on click in ASP.NET

ASP.Net 2.0 uses the new ClientScript function...
Button1.Attributes.Add("onclick", "this.disabled=true;" + ClientScript.GetPostBackEventReference(Button1, "").ToString())
9/9/2007 9:48 PM | Graeme
Comments have been closed on this topic.

Powered by: