468,253 Members | 1,296 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,253 developers. It's quick & easy.

Button click once

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

Nov 18 '05 #1
5 3184
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 Booth" wrote:
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

Nov 18 '05 #2
Jos
Jon Booth wrote:
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'; ).

--

Jos
Nov 18 '05 #3
Hi Jon,

You might also want to investigate this technique:

http://www.metabuilders.com/Tools/OneClick.aspx

"Jon Booth" <jo*******@nusystems.com.au> wrote in message
news:uJ**************@TK2MSFTNGP10.phx.gbl...
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


Nov 18 '05 #4

Jon Booth wrote:
*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
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

Nov 18 '05 #5
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.B utton1.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

"Jos" <jo***************@fastmail.fm> wrote in message
news:ui*************@TK2MSFTNGP12.phx.gbl...
Jon Booth wrote:
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'; ).

--

Jos

Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Yaqian Fang | last post: by
8 posts views Thread by Galahad | last post: by
6 posts views Thread by Michael Johnson Jr. | last post: by
8 posts views Thread by Lee | last post: by
3 posts views Thread by Imran Aziz | last post: by
16 posts views Thread by Barry Gilmore | last post: by
9 posts views Thread by mosscliffe | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.