473,395 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

disable button after confirmation message

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???
Oct 20 '06 #1
1 2952
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???
Oct 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dennis Allen | last post by:
Hi. On my online ordering form I use browser cookies to keep track of user items. My confirmation page reads: "If any of this information is incorrect, please go back to the order form and...
2
by: techfuzz | last post by:
I scoured this group and others looking for the best way to disable a button after the first click to prevent multiple submissions, but never did find anything that worked like they said it would. ...
14
by: Sinity | last post by:
Anyone knows the method/codes to disable the clicked button after first click by using .aspx-- to prevent people to click many time when waiting for the server response. I tried to do this by...
3
by: vcornjamb | last post by:
Hello, I am developing a web form that contains some buttons and a data grid which has as its last column link buttons that will delete the data associated with that row. Everything works fine,...
5
by: Samy | last post by:
Hi There, I have a label in a datagrid which I make it a input type = radio in ItemDataBound so that radio buttons are shown in the datagrid. This is how I have it... ASPX... <asp:Label...
1
by: Agnes | last post by:
I need to disable the exit button in the form . However, the min. and max. button need to keep it How ? Thanks a lot From Agnes
6
by: yxq | last post by:
Hello, How to disable the UAC function in Vista using API? Thank you
8
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I disable the right mouse button? -----------------------------------------------------------------------...
0
by: Eraser | last post by:
Hi to all .NET guru guys... I have a problem in my delete button inside gridview. How to avoid postback on when i select cancel on confirmation message? But postback is okay on Ok confirmation....
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.