Popup confirmation before ASP.NET Form Submit

J

John Straumann

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.
 
S

sloan

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.WebControl 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);
}
}
}
 
J

John Straumann

Hi Mark:

Thanks for the note. My apologies as I neglected to mention that the popup
window needs to display a "terms and conditions" document (so a fairly large
amount of text) and then react to the click of the "OK" button. I tried to
put a large string in the code below but it did not work. I use mostly code
behind files, but would it be possible to declare a variable in ASP.NET
script that holds the text, and then use the variable name in the return
confirm?

John.
 
S

sloan

You can try lots of returns in the long string message.

I would look at Telerik, as they have a form of a "Modal Window" for
Asp.Net.





John Straumann said:
Hi Mark:

Thanks for the note. My apologies as I neglected to mention that the popup
window needs to display a "terms and conditions" document (so a fairly
large amount of text) and then react to the click of the "OK" button. I
tried to put a large string in the code below but it did not work. I use
mostly code behind files, but would it be possible to declare a variable
in ASP.NET script that holds the text, and then use the variable name in
the return confirm?

John.
 

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,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top