Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Disable on button click

Reply
Thread Tools

Disable on button click

 
 
Barry Gilmore
Guest
Posts: n/a
 
      10-17-2005
Is there a way to disable a button after it is clicked?

I am trying to avoid having someone click on it twice while they wait for it
to process.

Thank you!


 
Reply With Quote
 
 
 
 
Ken Dopierala Jr.
Guest
Posts: n/a
 
      10-17-2005
Hi Barry,

This should work:

Button1.Attribute.Add("onclick", "this.disabled = true;
document.Form1.submit(); return false;")

I didn't test it but I know you need to submit the form yourself and cancle
the event bubble on the submit button. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"Barry Gilmore" <> wrote in message
news:roQ4f.469$...
> Is there a way to disable a button after it is clicked?
>
> I am trying to avoid having someone click on it twice while they wait for

it
> to process.
>
> Thank you!
>
>



 
Reply With Quote
 
 
 
 
=?Utf-8?B?U3JlZWppdGggUmFt?=
Guest
Posts: n/a
 
      10-17-2005
adding following code in the onClick event (javascript), will stop the user
from pressing it again

document.getElementById('buttonname').disabled='tr ue';


"Barry Gilmore" wrote:

> Is there a way to disable a button after it is clicked?
>
> I am trying to avoid having someone click on it twice while they wait for it
> to process.
>
> Thank you!
>
>
>

 
Reply With Quote
 
S. Justin Gengo
Guest
Posts: n/a
 
      10-17-2005
Barry,

I have a javascript that first makes a call to .net's built in
authentication scripts to make certain a form is submittable (you wouldn't
want to disable a button if the clientside script decides it's not valid and
doesn't submit thus stranding the user) and then disables a second click of
said button.

The code is available as part of a Javascript component that is free for
download from my website as a Visual Studio.Net 2003 project. Even if you
don't want to use the whole component (it has other scripts such as open a
centered popup window, click a button when the enter key is pressed while in
a text box, scroll to an element on the page, etc.) you could always strip
out the code you want. All the components on my site are free, all come with
complete source code, and there is a help file you may download if you'd
like.

You may download the component from here:
http://www.aboutfortunate.com?page=javascript

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Barry Gilmore" <> wrote in message
news:roQ4f.469$...
> Is there a way to disable a button after it is clicked?
>
> I am trying to avoid having someone click on it twice while they wait for
> it to process.
>
> Thank you!
>
>



 
Reply With Quote
 
S. Justin Gengo
Guest
Posts: n/a
 
      10-17-2005
Ken,

That will work, but what if the form isn't valid. Now the user can't fix and
resubmit...


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Ken Dopierala Jr." <> wrote in message
news:...
> Hi Barry,
>
> This should work:
>
> Button1.Attribute.Add("onclick", "this.disabled = true;
> document.Form1.submit(); return false;")
>
> I didn't test it but I know you need to submit the form yourself and
> cancle
> the event bubble on the submit button. Good luck! Ken.
>
> --
> Ken Dopierala Jr.
> For great ASP.Net web hosting try:
> http://www.webhost4life.com/default.asp?refid=Spinlight
> If you sign up under me and need help, email me.
>
> "Barry Gilmore" <> wrote in message
> news:roQ4f.469$...
>> Is there a way to disable a button after it is clicked?
>>
>> I am trying to avoid having someone click on it twice while they wait for

> it
>> to process.
>>
>> Thank you!
>>
>>

>
>



 
Reply With Quote
 
Bishoy George
Guest
Posts: n/a
 
      10-18-2005
Why using javascript?
It can be done very simply by C# code...

private void Button1_Click(object sender, System.EventArgs e)
{
Button1.Enabled = false;
}

Bishoy
-------

"Barry Gilmore" <> wrote in message
news:roQ4f.469$...
> Is there a way to disable a button after it is clicked?
>
> I am trying to avoid having someone click on it twice while they wait for
> it to process.
>
> Thank you!
>
>



 
Reply With Quote
 
JIMCO Software
Guest
Posts: n/a
 
      10-18-2005
Bishoy George wrote:
> Why using javascript?
> It can be done very simply by C# code...
>
> private void Button1_Click(object sender, System.EventArgs e)
> {
> Button1.Enabled = false;
> }
>


I think what he's trying to do is prevent someone from submitting a form
twice. Doing that in server-side code wouldn't not work.

--
Jim Cheshire
JIMCO Software
http://www.jimcosoftware.com




 
Reply With Quote
 
Bishoy George
Guest
Posts: n/a
 
      10-18-2005
"JIMCO Software" <> wrote in message
news:...
> Bishoy George wrote:
>> Why using javascript?
>> It can be done very simply by C# code...
>>
>> private void Button1_Click(object sender, System.EventArgs e)
>> {
>> Button1.Enabled = false;
>> }
>>

>
> I think what he's trying to do is prevent someone from submitting a form
> twice. Doing that in server-side code wouldn't not work.
>
> --
> Jim Cheshire
> JIMCO Software
> http://www.jimcosoftware.com

--------------------------------------------------------------

It is working with me.
I think if you revised what Mr.Barry Gilmore wanted, you may find my code
efficient.

Bishoy
http://bishoy.com


 
Reply With Quote
 
JIMCO Software
Guest
Posts: n/a
 
      10-18-2005
Bishoy George wrote:
>
> It is working with me.
> I think if you revised what Mr.Barry Gilmore wanted, you may find my
> code efficient.
>


Bishoy,

If you set the Enabled property of the button in server-side code, it only
affects the button when the page is rendered AFTER the postback. That won't
prevent someone from clicking the Submit button twice on a form. In order
to do that, you need to disable the button on the client immediately after
the form is submitted but before it actually POSTs.

Your code will not meet that need.

--
Jim Cheshire
JIMCO Software
http://www.jimcosoftware.com




 
Reply With Quote
 
Bishoy George
Guest
Posts: n/a
 
      10-18-2005
I tried the code submitted by Ken Dopierala Jr.
It disable the button for a second then when the page is refreshed due to
post back, it is enabled again.

Also the code of Sreejith Ram is not working.

Bishoy
http://bishoy.com
-----------------------------------------------------

"Barry Gilmore" <> wrote in message
news:roQ4f.469$...
> Is there a way to disable a button after it is clicked?
>
> I am trying to avoid having someone click on it twice while they wait for
> it to process.
>
> Thank you!
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to fire both event button click and textchanged when button is click and text is changed Amy ASP .Net 0 06-01-2006 02:33 PM
image button click event fires before click event of button Purvi T ASP .Net 0 10-19-2004 06:19 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Building Controls 1 05-28-2004 06:23 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net 2 05-25-2004 11:45 PM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Datagrid Control 0 05-25-2004 01:45 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57