473,396 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Disable on button click

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!
Nov 19 '05 #1
16 3395
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" <no**********@yahoo.com> wrote in message
news:ro**************@tornado.rdc-kc.rr.com...
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!

Nov 19 '05 #2
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!

Nov 19 '05 #3
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" <no**********@yahoo.com> wrote in message
news:ro**************@tornado.rdc-kc.rr.com...
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!

Nov 19 '05 #4
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." <kd*********@wi.rr.com> wrote in message
news:uF*************@tk2msftngp13.phx.gbl...
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" <no**********@yahoo.com> wrote in message
news:ro**************@tornado.rdc-kc.rr.com...
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!


Nov 19 '05 #5
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" <no**********@yahoo.com> wrote in message
news:ro**************@tornado.rdc-kc.rr.com...
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!

Nov 19 '05 #6
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


Nov 19 '05 #7
"JIMCO Software" <co*******@jimcosoftware.com> wrote in message
news:uP**************@TK2MSFTNGP14.phx.gbl...
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
Nov 19 '05 #8
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


Nov 19 '05 #9
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" <no**********@yahoo.com> wrote in message
news:ro**************@tornado.rdc-kc.rr.com...
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!

Nov 19 '05 #10
Hi Bishoy,

That is what it is supposed to do. Let's say you are doing a credit card
payment. It makes sure the user can only click once. Then after processing
is done they are redirected to a success or failure page. It also lets the
user know that they can only click the button once. On your site I can get
in over a dozen clicks before the page comes back to alert me. This also
means I posted 10 requests to your server instead of just one. If you were
doing a database app that required a few seconds to process and has multiple
steps it will really get hammered and you'll need to rollback 9 transactions
that may have started before the first transaction completed. While you
should have the logic to rollback those transactions in your app it is best
to do what you can to make sure you only need to executed a minimum number
of times. 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.

"Bishoy George" <bi****@bishoy.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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" <no**********@yahoo.com> wrote in message
news:ro**************@tornado.rdc-kc.rr.com...
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!


Nov 19 '05 #11
Hi Ken,
Your opinion is very reasonable.

But, I want an extra code to prevent the disabled button by adding
attributed from become active again.

Thanks.
Bishoy

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

"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi Bishoy,

That is what it is supposed to do. Let's say you are doing a credit card
payment. It makes sure the user can only click once. Then after
processing
is done they are redirected to a success or failure page. It also lets
the
user know that they can only click the button once. On your site I can
get
in over a dozen clicks before the page comes back to alert me. This also
means I posted 10 requests to your server instead of just one. If you
were
doing a database app that required a few seconds to process and has
multiple
steps it will really get hammered and you'll need to rollback 9
transactions
that may have started before the first transaction completed. While you
should have the logic to rollback those transactions in your app it is
best
to do what you can to make sure you only need to executed a minimum number
of times. 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.

"Bishoy George" <bi****@bishoy.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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" <no**********@yahoo.com> wrote in message
news:ro**************@tornado.rdc-kc.rr.com...
> 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!
>
>



Nov 19 '05 #12
Well Bishoy, I think the issue we trying to address is , if the user click
multiple times on submit button, the client browser would send multiple post
requests to the web server. This happens a lot when the client connection is
slow. Our code doesnt have any control on this because the browser would
think these are 2 diffrent posts by the user.

The simplest solution for it is to stop the user from clicking multiple
times by disabling the button at clientside after the first click. .so that
multiple requests are not send to the server by the browser. Like Justin
Gengo pointed this wouldnt work if you have validators though ..

Once you are at the Server Side OnClick event, you would be able to take the
additional step of disabling the button , clearing form data, redirecting the
page etc etc depending on the requirement of your app. But if you disable the
submit button for good, how will the user make the next submit?

"Bishoy George" wrote:
Hi Ken,
Your opinion is very reasonable.

But, I want an extra code to prevent the disabled button by adding
attributed from become active again.

Thanks.
Bishoy

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

"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi Bishoy,

That is what it is supposed to do. Let's say you are doing a credit card
payment. It makes sure the user can only click once. Then after
processing
is done they are redirected to a success or failure page. It also lets
the
user know that they can only click the button once. On your site I can
get
in over a dozen clicks before the page comes back to alert me. This also
means I posted 10 requests to your server instead of just one. If you
were
doing a database app that required a few seconds to process and has
multiple
steps it will really get hammered and you'll need to rollback 9
transactions
that may have started before the first transaction completed. While you
should have the logic to rollback those transactions in your app it is
best
to do what you can to make sure you only need to executed a minimum number
of times. 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.

"Bishoy George" <bi****@bishoy.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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" <no**********@yahoo.com> wrote in message
news:ro**************@tornado.rdc-kc.rr.com...
> 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!
>
>



Nov 19 '05 #13
Sreejith Ram wrote:

The simplest solution for it is to stop the user from clicking
multiple times by disabling the button at clientside after the first
click. .so that multiple requests are not send to the server by the
browser. Like Justin Gengo pointed this wouldnt work if you have
validators though ..


The following will work even if you have validation controls:

System.Text.StringBuilder sb = new StringBuilder();
sb.Append("if (typeof(Page_ClientValidate) == 'function') { ");
sb.Append("if (Page_ClientValidate() == false) { return false; }} ");
sb.Append("this.value = 'Please wait...';");
sb.Append("this.disabled = true;");
sb.Append(Page.GetPostBackEventReference(btnSubmit ));
sb.Append(";");
btnSubmit.Attributes.Add("onclick", sb.ToString());

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


Nov 19 '05 #14
thanks

"JIMCO Software" wrote:
Sreejith Ram wrote:

The simplest solution for it is to stop the user from clicking
multiple times by disabling the button at clientside after the first
click. .so that multiple requests are not send to the server by the
browser. Like Justin Gengo pointed this wouldnt work if you have
validators though ..


The following will work even if you have validation controls:

System.Text.StringBuilder sb = new StringBuilder();
sb.Append("if (typeof(Page_ClientValidate) == 'function') { ");
sb.Append("if (Page_ClientValidate() == false) { return false; }} ");
sb.Append("this.value = 'Please wait...';");
sb.Append("this.disabled = true;");
sb.Append(Page.GetPostBackEventReference(btnSubmit ));
sb.Append(";");
btnSubmit.Attributes.Add("onclick", sb.ToString());

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


Nov 19 '05 #15
Jimco,

Yes, that's what my disable submit function (submitted above) does.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"JIMCO Software" <co*******@jimcosoftware.com> wrote in message
news:u4****************@tk2msftngp13.phx.gbl...
Sreejith Ram wrote:

The simplest solution for it is to stop the user from clicking
multiple times by disabling the button at clientside after the first
click. .so that multiple requests are not send to the server by the
browser. Like Justin Gengo pointed this wouldnt work if you have
validators though ..


The following will work even if you have validation controls:

System.Text.StringBuilder sb = new StringBuilder();
sb.Append("if (typeof(Page_ClientValidate) == 'function') { ");
sb.Append("if (Page_ClientValidate() == false) { return false; }} ");
sb.Append("this.value = 'Please wait...';");
sb.Append("this.disabled = true;");
sb.Append(Page.GetPostBackEventReference(btnSubmit ));
sb.Append(";");
btnSubmit.Attributes.Add("onclick", sb.ToString());

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

Nov 19 '05 #16
S. Justin Gengo wrote:
Jimco,

Yes, that's what my disable submit function (submitted above) does.


Sorry if reposted. I posted in response to a "doesn't work with validators"
post. I hide read posts, do unless I happen to remember a previous post's
content, it's gone clear into another realm by the time I might respond. ;)

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


Nov 19 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: nntp | last post by:
I have a set of links which I want search engines to crawl them, but I want to disable them from my visitors, so I will ask the link owners to pay me to let me enable them. <a disabled...
1
by: Suni | last post by:
Hi everybody, But what I am trying to do is like, there are 2 forms, and if I click on the button in form1, it'll open up form2 and disable the button in form1. Then when I click on the button in...
2
by: techfuzz | last post by:
I scoured this group and others looking for the best way to disable a button after the first click to prevent multiple submissions, but never did find anything that worked like they said it would. ...
14
by: Sinity | last post by:
Anyone knows the method/codes to disable the clicked button after first click by using .aspx-- to prevent people to click many time when waiting for the server response. I tried to do this by...
3
by: Jeff | last post by:
I have a payment form with a submit button. A large percentage of users double-click the submit button thus submitting their payment information twice. I would like to use javascript to disable...
0
by: Robert Ladd | last post by:
Hi, I'm trying to disable the asp.net calendar control from a javascript function, but it doesn't disable the doPostBack. To simplify the situation, assume a page with 4 controls. A...
4
by: Buddy Ackerman | last post by:
If I put client side code to disable a button (so that a user doesn't click it twice and double post the form) then teh button doesn't get posted with the form and the button's server-side click...
0
by: Ahmad Jalil Qarshi | last post by:
Hi! I have a problem while developing some webpages.The Problem is that:- How We Can Disable The Controls Of One Web Form From Other Web Form In Asp.net? Explanation:- There Should Be Two...
8
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I disable the right mouse button? -----------------------------------------------------------------------...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.