Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

disable button on click

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

<script runat="server">
sub submit_it (Obj as Object, e as EventArgs)
if (Page.IsValid) then
BtnSubmit.text = Not(BtnSubmit.Enabled)
end if
End sub
</script>


 
Reply With Quote
 
 
 
 
Infant Newbie
Guest
Posts: n/a
 
      12-05-2003
set a page-level variable , boolean boolAllow
then in ok click event

if boolAllow = true then
return
bAllow = true
btnOK.enable = false
DO YOUR STUFF HERE
btnok.enable = true ---- if u want
boolAllow = false

MIND - NOT REAL CODE ABOVE

bart
http://www.meshcode.net
"nicholas" <> wrote in message
news:eWE$...
> 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:
>
> <script runat="server">
> sub submit_it (Obj as Object, e as EventArgs)
> if (Page.IsValid) then
> BtnSubmit.text = Not(BtnSubmit.Enabled)
> end if
> End sub
> </script>
>
>



 
Reply With Quote
 
 
 
 
S. Justin Gengo
Guest
Posts: n/a
 
      12-05-2003
Nicholas,

This javascript will do the trick for you. It only disables the button if
the form passes validation:

<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>

In VB.Net Attach it to your button like so:

SubmitButton.Attributes.Add("onClick", "javascript: return
disableSubmit();")


If you'd like I've encapsulated this script and a method for attaching it to
any button in a component I offer for free on my web site,
www.aboutfortunate.com.

Just go to the code library and then click the Javascript button in the menu
on the left. The entire component's source code is available (as a .Net
project) and it contains some other useful javascripts.


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche


"nicholas" <> wrote in message
news:eWE$...
> 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:
>
> <script runat="server">
> sub submit_it (Obj as Object, e as EventArgs)
> if (Page.IsValid) then
> BtnSubmit.text = Not(BtnSubmit.Enabled)
> end if
> End sub
> </script>
>
>



 
Reply With Quote
 
Kathy Burke
Guest
Posts: n/a
 
      12-05-2003

btnSubmit.enabled = False

hth,

Kathy

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
nicholas
Guest
Posts: n/a
 
      12-05-2003
Although I don't realy understand what you are trying to do, this is what I
tried without succes:

<script runat="server">
dim boolAllow as boolean
sub submit_it (Obj as Object, e as EventArgs)
if boolAllow = true then
return
boolAllow = true
BtnSubmit.enabled = false
boolAllow = false
if (Page.IsValid) then
BtnSubmit.enabled = False
end if
end if
End sub
</script>



"Infant Newbie" <> wrote in message
news:bqq5j8$1nl$...
> set a page-level variable , boolean boolAllow
> then in ok click event
>
> if boolAllow = true then
> return
> bAllow = true
> btnOK.enable = false
> DO YOUR STUFF HERE
> btnok.enable = true ---- if u want
> boolAllow = false
>
> MIND - NOT REAL CODE ABOVE
>
> bart
> http://www.meshcode.net
> "nicholas" <> wrote in message
> news:eWE$...
> > 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:
> >
> > <script runat="server">
> > sub submit_it (Obj as Object, e as EventArgs)
> > if (Page.IsValid) then
> > BtnSubmit.text = Not(BtnSubmit.Enabled)
> > end if
> > End sub
> > </script>
> >
> >

>
>



 
Reply With Quote
 
nicholas
Guest
Posts: n/a
 
      12-05-2003
That's what I tried first, but that does not work (although it doesn't
generate an error):

<script runat="server">
sub submit_it (Obj as Object, e as EventArgs)
BtnSubmit.enabled = false
End sub
</script>

"Kathy Burke" <> wrote in message
news:...
>
> btnSubmit.enabled = False
>
> hth,
>
> Kathy
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
nicholas
Guest
Posts: n/a
 
      12-08-2003
I tried to send you a mail, but your I got this error:
450 <>: Recipient address rejected: Domain not
found

You'll find a mail link on my web site: www.squaresweb.com

Thanks a lot for your help.



"Infant Newbie" <> wrote in message
news:bqvs95$ulf$...
> if u still need help send me mail and i will send u a working example
>
>
>
>
> http://www.meshcode.net
>
>
> "nicholas" <> wrote in message
> news:...
> > Although I don't realy understand what you are trying to do, this is

what
> I
> > tried without succes:
> >
> > <script runat="server">
> > dim boolAllow as boolean
> > sub submit_it (Obj as Object, e as EventArgs)
> > if boolAllow = true then
> > return
> > boolAllow = true
> > BtnSubmit.enabled = false
> > boolAllow = false
> > if (Page.IsValid) then
> > BtnSubmit.enabled = False
> > end if
> > end if
> > End sub
> > </script>
> >
> >
> >
> > "Infant Newbie" <> wrote in message
> > news:bqq5j8$1nl$...
> > > set a page-level variable , boolean boolAllow
> > > then in ok click event
> > >
> > > if boolAllow = true then
> > > return
> > > bAllow = true
> > > btnOK.enable = false
> > > DO YOUR STUFF HERE
> > > btnok.enable = true ---- if u want
> > > boolAllow = false
> > >
> > > MIND - NOT REAL CODE ABOVE
> > >
> > > bart
> > > http://www.meshcode.net
> > > "nicholas" <> wrote in message
> > > news:eWE$...
> > > > 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:
> > > >
> > > > <script runat="server">
> > > > sub submit_it (Obj as Object, e as EventArgs)
> > > > if (Page.IsValid) then
> > > > BtnSubmit.text = Not(BtnSubmit.Enabled)
> > > > end if
> > > > End sub
> > > > </script>
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
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