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.
CancelButtonCon firmInsertion (this.Page , button1 ); // is all I need on the
page.
public enum AppendOrder
{
BEFORE_CURRENT_ ITEMS = 1,
AFTER_CURRENT_I TEMS = 2
}
public class ObjectUtilityLi b
{
private ObjectUtilityLi b()
{
}
/// <summary>
/// Attaches a 'Are you sure you want to cancel?' javascript confirm
message to a webcontrol.
/// </summary>
/// <param name="TargetPag e">The target page.</param>
/// <param name="c">The control to attach the javascript cancel
confirm.</param>
public static void CancelButtonCon firmInsertion(P age TargetPage,
System.Web.UI.W ebControls.WebC ontrol c)
{
string jsFunction = "return confirm('Are you sure you would like
to cancel?');";
//jsFunction = "return true;";
AppendAttribute (c, "onClick", jsFunction,
Web.Utilities.A ppendOrder.AFTE R_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.Web Control c, string eventName,
string newScript, AppendOrder ao)
{
string currentAttrib;
currentAttrib = c.Attributes[eventName];
if (!(currentAttri b == null))
{
if (ao == AppendOrder.BEF ORE_CURRENT_ITE MS)
{
c.Attributes.Ad d(eventName, newScript + currentAttrib);
}
else
{
c.Attributes.Ad d(eventName, currentAttrib + newScript);
}
}
else
{
c.Attributes.Ad d(eventName, newScript);
}
}
}
"John Straumann" <js********@hot mail.comwrote in message
news:67******** *************** ***********@mic rosoft.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.