disable button after confirmation message

G

Guest

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

Guest

Nevermind...I think I found something here:

http://geekswithblogs.net/anjanaonline/archive/2006/06/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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top