Button click once

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
 
G

Guest

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
 
W

weichung

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
 
J

Jos

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';).
 
J

Jon Booth

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top