Javascript with Submit Button

  • Thread starter Thread starter James
  • Start date Start date
J

James

I have an ASP button on my form that will e-mail several people, and I'd
like to disable it once the user clicks on it, so that they can only click
on it once.

I have a client side javascript confirmation box that says 'Are you
sure...?' and when a user clicks OK, it seems like I have two options. I
can either disable the box, or have the submit work. When I disable it, it
doesn't post. I'm returning true/false based on what they click in the
confirm box like this:

document.getElementById('pbSend').disabled = true;

if (confirm('Are you sure you want to send this?') == true)
{
return true;
}
else
{
document.getElementById('pbSend').disabled = false;
return false;
}

Any thoughts?
 
you need to disable it after the submit. either add the disable to the
onsubmit routine or use a timer:


if (!confirm('Are you sure you want to send this?'))
return false;
else
{
window.setTimeout("document.getElementById('pbSend').disabled =
false",1);
return true;
}

-- bruce (sqlwork.com)
 
Your example may have issues with client side valiation. Try running the
post back event reference then disable the button. An example is:

private void btnSendMassEmail_PreRender(object sender, System.EventArgs e)
{
Button btn = (Button) sender;
btn.Attributes.Add("onclick",
string.Format("{0};this.disabled=true;",
GetPostBackEventReference(btn)));

}
 
Back
Top