470,815 Members | 1,133 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

Popup confirmation before ASP.NET Form Submit

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.

Oct 31 '08 #1
4 14307
"John Straumann" <js********@hotmail.comwrote in message
news:67**********************************@microsof t.com...
Can anyone suggest how I can accomplish this?
<asp:Button ID="cmdSubmit" runat="server" Text = "Submit"
OnClick="cmdSubmit_Click" OnClientClick="return confirm('Are you sure?');"
/>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 31 '08 #2

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.

Oct 31 '08 #3
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.

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:uf**************@TK2MSFTNGP02.phx.gbl...
"John Straumann" <js********@hotmail.comwrote in message
news:67**********************************@microsof t.com...
>Can anyone suggest how I can accomplish this?

<asp:Button ID="cmdSubmit" runat="server" Text = "Submit"
OnClick="cmdSubmit_Click" OnClientClick="return confirm('Are you sure?');"
/>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Oct 31 '08 #4

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" <js********@hotmail.comwrote in message
news:66**********************************@microsof t.com...
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.

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:uf**************@TK2MSFTNGP02.phx.gbl...
>"John Straumann" <js********@hotmail.comwrote in message
news:67**********************************@microso ft.com...
>>Can anyone suggest how I can accomplish this?

<asp:Button ID="cmdSubmit" runat="server" Text = "Submit"
OnClick="cmdSubmit_Click" OnClientClick="return confirm('Are you
sure?');" />
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 3 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by sudhaoncyberworld | last post: by
4 posts views Thread by Gabriella | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.