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" <mu********@hotmail.com> wrote in message
news:eW*************@TK2MSFTNGP11.phx.gbl...
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>