Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Disable button after first click

Reply
Thread Tools

Disable button after first click

 
 
Sinity
Guest
Posts: n/a
 
      11-12-2003
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?VmlqYXkgR2FuZ2E=?=
Guest
Posts: n/a
 
      11-12-2003
Using Javascript(Client side
You can add a javascript onclick handler in the .cs file as unde

string x = "document.Form1.Button1.disabled=true"
this.Button1.Attributes.Add("onclick",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(object sender, System.EventArgs e)
this.Button1.Enabled=false


 
Reply With Quote
 
 
 
 
S. Justin Gengo
Guest
Posts: n/a
 
      11-12-2003
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="javascript">
<!--
var submitcount=0;

function disableSubmit()
{
if (typeof(Page_ClientValidate)=='function')
{
if (Page_ClientValidate() == 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.Attributes.Add("onClick", "javascript: return
disableSubmit();")


Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche


"Sinity" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Homa
Guest
Posts: n/a
 
      11-12-2003
> if (Page_ClientValidate() == true)
> {
> return checkSubmit();
> }
> else
> {
> return true; <<< ----- You mean return false; right?
> }


Homa Wong


"S. Justin Gengo" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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="javascript">
> <!--
> var submitcount=0;
>
> function disableSubmit()
> {
> if (typeof(Page_ClientValidate)=='function')
> {
> if (Page_ClientValidate() == 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.Attributes.Add("onClick", "javascript: return
> disableSubmit();")
>
>
> Sincerely,
>
> --
> S. Justin Gengo, MCP
> Web Developer
>
> Free code library at:
> www.aboutfortunate.com
>
> "Out of chaos comes order."
> Nietzche
>
>
> "Sinity" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > 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
> >
> >

 
Reply With Quote
 
Sinity
Guest
Posts: n/a
 
      11-13-2003
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" <(E-Mail Removed)> glsD
:(E-Mail Removed)...
> 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="javascript">
> <!--
> var submitcount=0;
>
> function disableSubmit()
> {
> if (typeof(Page_ClientValidate)=='function')
> {
> if (Page_ClientValidate() == 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.Attributes.Add("onClick", "javascript: return
> disableSubmit();")
>
>
> Sincerely,
>
> --
> S. Justin Gengo, MCP
> Web Developer
>
> Free code library at:
> www.aboutfortunate.com
>
> "Out of chaos comes order."
> Nietzche
>
>
> "Sinity" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      11-13-2003
If IsPostBack Then
button.enabled = false
End If

"Sinity" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
S. Justin Gengo
Guest
Posts: n/a
 
      11-13-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> > if (Page_ClientValidate() == true)
> > {
> > return checkSubmit();
> > }
> > else
> > {
> > return true; <<< ----- You mean return false; right?
> > }

>
> Homa Wong
>
>
> "S. Justin Gengo" <(E-Mail Removed)> wrote in message

news:<(E-Mail Removed)>...
> > 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="javascript">
> > <!--
> > var submitcount=0;
> >
> > function disableSubmit()
> > {
> > if (typeof(Page_ClientValidate)=='function')
> > {
> > if (Page_ClientValidate() == 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.Attributes.Add("onClick", "javascript: return
> > disableSubmit();")
> >
> >
> > Sincerely,
> >
> > --
> > S. Justin Gengo, MCP
> > Web Developer
> >
> > Free code library at:
> > www.aboutfortunate.com
> >
> > "Out of chaos comes order."
> > Nietzche
> >
> >
> > "Sinity" <(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> > > 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
> > >
> > >



 
Reply With Quote
 
Homa Wong
Guest
Posts: n/a
 
      11-13-2003

?? 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!
 
Reply With Quote
 
S. Justin Gengo
Guest
Posts: n/a
 
      11-13-2003
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_ClientValidate, 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> ?? 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!



 
Reply With Quote
 
Homa
Guest
Posts: n/a
 
      11-13-2003
haha,

...."Out of chaos comes order."


Homa Wong

"S. Justin Gengo" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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_ClientValidate, 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >
> > ?? 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!

 
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
Disable a button on first click Stuart Quinn ASP .Net 6 08-07-2006 06:45 PM
Disable submit button after click but fire validators? Chris Ashley ASP .Net 1 12-16-2005 11:39 AM
Disable button after first click Sinity ASP .Net 0 11-12-2003 05:35 PM
Disable button after first click Sinity ASP General 1 11-12-2003 05:17 PM
Datalist selects Item after first click, but does apply the SelectedItemTemplate after the second click only Dirk Meusel ASP .Net 1 08-19-2003 09:56 AM



Advertisments