Button click once

  • Thread starter Thread starter Jon Booth
  • Start date Start date
J

Jon Booth

Hi All,
I'm trying to create a button that once clicked will disable itself (so as
not to be clicked twice)

I have the following in my cs
Button1.Attributes.Add("onClick","return
document.Form1.Button1.disabled=true;");

It disables the button but does not perform the post back. What am I doing
wrong?

If I remove the line it posts back fine.

Thanks
Jon
 
Hi
Place button1.enabled = false on the button click event. This will disable
the button after postback, because, the click event is only processed after
postback. Thanks
Ibrahim
 
Jon said:
*Hi All,
I'm trying to create a button that once clicked will disable itsel
(so as
not to be clicked twice)

I have the following in my cs
Button1.Attributes.Add("onClick","return
document.Form1.Button1.disabled=true;");

It disables the button but does not perform the post back. What am
doing
wrong?

If I remove the line it posts back fine.

Thanks
Jon *

you want the button to be used only once? (and your button i
performing some action which requires a postback, is it?)

then just put this portion of code at the end of the button clic
event.

me.enable = false

By the way, is it a HTML button or a ASP.NET button


-
weichun
 
Jon said:
Hi All,
I'm trying to create a button that once clicked will disable itself
(so as not to be clicked twice)

I have the following in my cs
Button1.Attributes.Add("onClick","return
document.Form1.Button1.disabled=true;");

It disables the button but does not perform the post back. What am I
doing wrong?

If I remove the line it posts back fine.

It disables the button before the actual postback, which is hence aborted.

I saw a similar post a few weeks ago, and I remember that
one of the solutions was to use visibility instead of disabled.
(document.Form1.Button1.style.visibility='hidden';).
 
Thanks for the advice.
I've extended your suggestion of using styles. I have a second html button
that is disabled and hidden. When the user clicks the asp button its hidden
and the html button is displayed.

Button1.Attributes.Add("onClick","document.Form1.Button1.style.display='none
';document.Form1.Button2.style.display='block';");

I wanted to do it client side because I didn't want them to click it twice
by accident. rarely someon may want to submit twice in which case they can
go back to the page and do it.

Thanks for your help
Jon
 
Back
Top