473,686 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Disable button after first click

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 adding a java script for the button. But, useless..

Please help! Thank you
Nov 17 '05 #1
14 7183
Using Javascript(Clie nt side
You can add a javascript onclick handler in the .cs file as unde

string x = "document.Form1 .Button1.disabl ed=true"
this.Button1.At tributes.Add("o nclick",x)

To do the same on the server side

add the following to your button click event handler { i.e the function --private void Button1_Click(o bject sender, System.EventArg s e)
this.Button1.En abled=false
Nov 17 '05 #2
Sinity,

I'm just about to post the code to do this on my website, but here you go:

It stops the submit, but even better it calls some of the same .Net client
side code and doesn't disable the button if any required field validators
aren't valid and the page doesn't actually submit.

<script language="javas cript">
<!--
var submitcount=0;

function disableSubmit()
{
if (typeof(Page_Cl ientValidate)== 'function')
{
if (Page_ClientVal idate() == true)
{
return checkSubmit();
}
else
{
return true;
}
}
else
{
return checkSubmit();
}
}

function checkSubmit()
{
if (submitcount == 0)
{
submitcount++; return true;
}
else
{
alert('This form has already been submitted.'); return false;
}
}
//-->
</script>

Attach it to your button like so:

SubmitButton.At tributes.Add("o nClick", "javascript : return
disableSubmit() ;")
Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Sinity" <si****@msn.com > wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
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 adding a java script for the button. But, useless..

Please help! Thank you

Nov 17 '05 #3
> if (Page_ClientVal idate() == true)
{
return checkSubmit();
}
else
{
return true; <<< ----- You mean return false; right?
}
Homa Wong
"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message news:<ud******* *******@TK2MSFT NGP10.phx.gbl>. .. Sinity,

I'm just about to post the code to do this on my website, but here you go:

It stops the submit, but even better it calls some of the same .Net client
side code and doesn't disable the button if any required field validators
aren't valid and the page doesn't actually submit.

<script language="javas cript">
<!--
var submitcount=0;

function disableSubmit()
{
if (typeof(Page_Cl ientValidate)== 'function')
{
if (Page_ClientVal idate() == true)
{
return checkSubmit();
}
else
{
return true;
}
}
else
{
return checkSubmit();
}
}

function checkSubmit()
{
if (submitcount == 0)
{
submitcount++; return true;
}
else
{
alert('This form has already been submitted.'); return false;
}
}
//-->
</script>

Attach it to your button like so:

SubmitButton.At tributes.Add("o nClick", "javascript : return
disableSubmit() ;")
Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Sinity" <si****@msn.com > wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
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 adding a java script for the button. But, useless..

Please help! Thank you

Nov 17 '05 #4
As the server response is slow something because of the network traffic,
users click again and again.

how can I manage this problem in aspx level?

I am using VB.NET as the devevelopment tool
"S. Justin Gengo" <sj*****@aboutf ortunate.com> ¼¶¼g©ó¶l¥ó·s»D
:ud************ **@TK2MSFTNGP10 .phx.gbl...
Sinity,

I'm just about to post the code to do this on my website, but here you go:

It stops the submit, but even better it calls some of the same .Net client
side code and doesn't disable the button if any required field validators
aren't valid and the page doesn't actually submit.

<script language="javas cript">
<!--
var submitcount=0;

function disableSubmit()
{
if (typeof(Page_Cl ientValidate)== 'function')
{
if (Page_ClientVal idate() == true)
{
return checkSubmit();
}
else
{
return true;
}
}
else
{
return checkSubmit();
}
}

function checkSubmit()
{
if (submitcount == 0)
{
submitcount++; return true;
}
else
{
alert('This form has already been submitted.'); return false;
}
}
//-->
</script>

Attach it to your button like so:

SubmitButton.At tributes.Add("o nClick", "javascript : return
disableSubmit() ;")
Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Sinity" <si****@msn.com > wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
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 adding a java script for the button. But, useless..
Please help! Thank you


Nov 17 '05 #5
If IsPostBack Then
button.enabled = false
End If

"Sinity" <si****@msn.com > wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
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 adding a java script for the button. But, useless..

Please help! Thank you

Nov 17 '05 #6
No, "return false;" is correct. Try it out.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Homa" <ho******@yahoo .com> wrote in message
news:a9******** *************** ***@posting.goo gle.com...
if (Page_ClientVal idate() == true)
{
return checkSubmit();
}
else
{
return true; <<< ----- You mean return false; right?
}


Homa Wong
"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message

news:<ud******* *******@TK2MSFT NGP10.phx.gbl>. ..
Sinity,

I'm just about to post the code to do this on my website, but here you go:
It stops the submit, but even better it calls some of the same .Net client side code and doesn't disable the button if any required field validators aren't valid and the page doesn't actually submit.

<script language="javas cript">
<!--
var submitcount=0;

function disableSubmit()
{
if (typeof(Page_Cl ientValidate)== 'function')
{
if (Page_ClientVal idate() == true)
{
return checkSubmit();
}
else
{
return true;
}
}
else
{
return checkSubmit();
}
}

function checkSubmit()
{
if (submitcount == 0)
{
submitcount++; return true;
}
else
{
alert('This form has already been submitted.'); return false;
}
}
//-->
</script>

Attach it to your button like so:

SubmitButton.At tributes.Add("o nClick", "javascript : return
disableSubmit() ;")
Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Sinity" <si****@msn.com > wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
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 adding a java script for the button. But,

useless..
Please help! Thank you

Nov 17 '05 #7

?? But I thought you wrote "return true" ??

Homa Wong
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #8
Homa,

Now I've confused myself! Yes, it has to be "return true;".

This is because the submit button's click event fires off two different
asp.net javascripts. One is the javascript I'm tying into:
Page_ClientVali date, the other is a javascript that checks the required
field validators.

At the point in question inside of my javascript if the Button doesn't get
clicked (which is what "return false;" would cause then any validators on
the page wouldn't get displayed properly.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Homa Wong" <no*****@MyWorl d.com> wrote in message
news:eN******** ******@TK2MSFTN GP09.phx.gbl...

?? But I thought you wrote "return true" ??

Homa Wong
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #9
haha,

...."Out of chaos comes order."
Homa Wong

"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message news:<u6******* *******@TK2MSFT NGP11.phx.gbl>. ..
Homa,

Now I've confused myself! Yes, it has to be "return true;".

This is because the submit button's click event fires off two different
asp.net javascripts. One is the javascript I'm tying into:
Page_ClientVali date, the other is a javascript that checks the required
field validators.

At the point in question inside of my javascript if the Button doesn't get
clicked (which is what "return false;" would cause then any validators on
the page wouldn't get displayed properly.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Homa Wong" <no*****@MyWorl d.com> wrote in message
news:eN******** ******@TK2MSFTN GP09.phx.gbl...

?? But I thought you wrote "return true" ??

Homa Wong
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #10

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

Similar topics

1
5790
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 adding a java script for the button. But, useless.. Please help!
29
9770
by: lori3laz | last post by:
How do you disable the right click>view source option on web pages so people can't view your coding and copy it? What's the html I need to include in my website to utilize this feature? Thank you.
7
1856
by: nicholas | last post by:
how can I disable a button when the user clicks on it and the webform is validated. I want this to prevent the user from clicking twice and by this submitting the form twice. Thank you. This is what I tried, but it does nothing:
1
8158
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the first time the control is dynamically loaded, everything works fine. After that, if the control is loaded again from the page button event handler, the user controls events fail to fire on the first click NOTE: I (believe I) am rebuilding all...
1
1867
by: Tee | last post by:
Hi, I have a server side Button that with the code Button3.Attributes.Add("onclick", "javascript:document.all.disabled=True; return false;") but it don't work as it supposed to be, disable button and the return false prevent it submit back to server.
0
1054
by: megan_c | last post by:
Hi, I have several check boxes on a form which are bound to a database record. I'm having an issue with one of them. After loading and binding the controls, i disable and enable this one(I'll call it chkbox2) based on another check box value(call this one chkbox1). However, on the first click after enabling chkbox2, it is not being checked. After the first click it starts working properly.....any ideas?????
4
9041
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 event handler is not fired. Seems like a big hole in the ASP.NET form handling process. Any way around it and still use the button click event handler? --Buddy
6
2804
by: user | last post by:
Hello, With ASP.NET2, how to program a button's click ? For example, I have two button and when i click the first one, i would like that the second one will be click too (by programming) ... something like button2.click ??? Thanks for help ..
2
5207
by: William | last post by:
Hi I've created a page with only 'n blank table control on it. When clicking a button, the table populates with various textboxes and dropdown lists to make up a complete form. In the last row of the table, a submit button is added. Almost everything works fine. The form display, the user fills out the form and then click Submit. However, the first time the submit button is clicked, the Click event isn't raised. Just a simple...
0
8586
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8520
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9057
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8780
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7603
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6442
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.