Nevermind...I think I found something here:
http://geekswithblogs.net/anjanaonli.../21/82528.aspx
public void DisableAndConfirmButton(Button button, string confirmationMessage)
{
System.Text.StringBuilder sbValid = new System.Text.StringBuilder();
sbValid.Append("if (confirm('");
sbValid.Append(confirmationMessage);
sbValid.Append("')){");
sbValid.Append(" if (typeof(Page_DoPostBack) == 'function') { ");
sbValid.Append(" if (Page_DoPostBack () == false) { return false; }");
sbValid.Append(" }");
sbValid.Append(" this.disabled = true;");
sbValid.Append(" document.all.");
sbValid.Append(button.ID);
sbValid.Append(".disabled = true;");
//GetPostBackEventReference obtains a reference to a client-side script
function
// that causes the server to post back to the page.
sbValid.Append(this.Page.GetPostBackEventReference (button));
sbValid.Append(";");
sbValid.Append("}");
sbValid.Append("else {");
sbValid.Append(" return false;");
sbValid.Append("}");
button.Attributes.Add("onclick", sbValid.ToString());
}
I implemented it in my BasePage class so that I could use it with several
different buttons if I needed to. Also, I added the last few lines to the
StringBuilder because what was posted in the URL was submitting even if I
selected "No" to the confirmation message.
sbValid.Append("else {");
sbValid.Append(" return false;");
sbValid.Append("}");
Ideas, Comments, Thoughts???
Brian
"brianpmccullough" wrote:
I have an ASP.NET page that has a few buttons on it. One of the buttons
kicks off a long running process on the web server and I want to prevent the
user from clicking the button again while the long running process is working
(i.e. before the page completes it's "postback").
I tried something like so, but it didn't work:
<script language="javascript">
function confirmWinnerSelection(myBtn){
if (confirm('Are you sure?')) {
myBtn.disabled = 'diabled';
return true;
}
else
{
return false;
}
}
</script>
Then in my button's OnClick event I have the following:
OnClick="javascript: return confirmWinnerSelection(this);"
I think because I am disabling the button before the submission actually
take's place, it is not performing the postback. Is there anyway to get
around it???