This code is my "Cancel Page" confirmation.
If I pick "Yes" (to Cancel), my code behind (button) code runs, and
redirects me.
If I pick "No", I stay on the page.
CancelButtonConfirmInsertion (this.Page , button1 ); // is all I need on the
page.
public enum AppendOrder
{
BEFORE_CURRENT_ITEMS = 1,
AFTER_CURRENT_ITEMS = 2
}
public class ObjectUtilityLib
{
private ObjectUtilityLib()
{
}
/// <summary>
/// Attaches a 'Are you sure you want to cancel?' javascript confirm
message to a webcontrol.
/// </summary>
/// <param name="TargetPage">The target page.</param>
/// <param name="c">The control to attach the javascript cancel
confirm.</param>
public static void CancelButtonConfirmInsertion(Page TargetPage,
System.Web.UI.WebControls.WebControl c)
{
string jsFunction = "return confirm('Are you sure you would like
to cancel?');";
//jsFunction = "return true;";
AppendAttribute(c, "onClick", jsFunction,
Web.Utilities.AppendOrder.AFTER_CURRENT_ITEMS);
}
/// <summary>
/// Appends the attribute.
/// </summary>
/// <param name="c">The webcontrol to which the Javascript will be
appended.</param>
/// <param name="eventName">Name of the javascript event for the
control.</param>
/// <param name="newScript">The new script text.</param>
/// <param name="ao">The AppendOrder.</param>
public static void
AppendAttribute(System.Web.UI.WebControls.WebContr ol c, string eventName,
string newScript, AppendOrder ao)
{
string currentAttrib;
currentAttrib = c.Attributes[eventName];
if (!(currentAttrib == null))
{
if (ao == AppendOrder.BEFORE_CURRENT_ITEMS)
{
c.Attributes.Add(eventName, newScript + currentAttrib);
}
else
{
c.Attributes.Add(eventName, currentAttrib + newScript);
}
}
else
{
c.Attributes.Add(eventName, newScript);
}
}
}
"John Straumann" <js********@hotmail.comwrote in message
news:67**********************************@microsof t.com...
Hi all:
I have an ASP.NET form that submits info to the server, but the customer
wants a confirmation window to open when the user clicks "Submit", and
then the user would have to click "OK" on the popup window to have the
main form submit. I found some samples of using JavaScript to create a
popup window, but then the OnClick event for the form button runs the
JavaScript as opposed to the server side code.
Can anyone suggest how I can accomplish this?
Thanks.
John.