473,836 Members | 1,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 14509
"John Straumann" <js********@hot mail.comwrote in message
news:67******** *************** ***********@mic rosoft.com...
Can anyone suggest how I can accomplish this?
<asp:Button ID="cmdSubmit" runat="server" Text = "Submit"
OnClick="cmdSub mit_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.
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.

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**@markNOSPA Mrae.netwrote in message
news:uf******** ******@TK2MSFTN GP02.phx.gbl...
"John Straumann" <js********@hot mail.comwrote in message
news:67******** *************** ***********@mic rosoft.com...
>Can anyone suggest how I can accomplish this?

<asp:Button ID="cmdSubmit" runat="server" Text = "Submit"
OnClick="cmdSub mit_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********@hot mail.comwrote in message
news:66******** *************** ***********@mic rosoft.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**@markNOSPA Mrae.netwrote in message
news:uf******** ******@TK2MSFTN GP02.phx.gbl...
>"John Straumann" <js********@hot mail.comwrote in message
news:67******* *************** ************@mi crosoft.com...
>>Can anyone suggest how I can accomplish this?

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

Nov 3 '08 #5

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

Similar topics

2
5554
by: Matt | last post by:
Can form.submit() submit another form? In the following example, in page1.asp, it is fine to submit the current form: form1.submit(), and and I could see the value "Joe" in page2.asp. However, if I do: form3.submit(), then it couldn't go to page2.asp. Any ideas?? Thanks!! //page1.asp <html> <head> </head> <body onload="form1.submit()"> //OK!
4
3524
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I click a button on a pop-up window the javascript for that button click does a 'button.form.submit'. On the Server side there is a Button click event for this button, but for some reason it no longer fires. It worked fine before and everything...
2
9002
by: steggun | last post by:
How To: Popup Confirmation Dialog & Redirect in LinkButton_OnClick Hello All, I have a ASP.NET 2.0 (C#) web form with a LinkButton control. In the server-side code for the LinkButton_OnClick event, I need to do some processing and, if it succeeds, popup a confirmation dialog and redirect to a different page. How can I do this? Here's some pseudo-code:
1
1418
by: sudhaoncyberworld | last post by:
Hi all I am trying to submit the form and after form.submit line i am trying to open a url using window.open.... I found in some forum it is not possible to reach out the statement after the form.submit The alternate way is having a alert next to form.submit will execute the following statements.... this is ok...
4
8167
by: jwlum | last post by:
I have the following problem under Internet Explorer only: 1. User fills out form data (myform.php) and clicks a button that fires myFunction() 2. myFunction() spawns a "hello, world" popup page via window.open 3. myFunction() submits the main page's form via document.form.submit() 5. User closes popup window and clicks browser's Back button to return to form entry page 6. All the form data that the user had filled out is now blank...
4
21289
by: Gabriella | last post by:
Hi, I have a popup window that opens from a page on my website. This popup is a form with several fields. Upon submit button it redirects to a server side ASP page which writes all data to the DB. I would like the popup to close immediately after the submit button is clicked, and data is saved, (or cancel button) - but this does not happen.
1
10838
by: gbezas | last post by:
Hi All, I have added an event handler to redirect form.submit() to a newSubmit() method that I have defined (which does some additional processing before submitting the form). Additionally I have defined the relavant function method in the code for details) The issue is that when Icall targetForm._submit() method from the newSubmit() function the page I get an 'Object doesn't support this property or method' error I am using IE...
5
4737
by: Curious89 | last post by:
There are 3 buttons on a web page. On clicking each button a same popup window (say window1) opens up. Now there is another button on this popup window (window1), which further opens up to another popup window (say window2). On selecting some value from the 'window2', that value is passed onto the 'window1'. There is a 'Find' link on a 'window1', which calls a javascript function 'clicked()': <head> <% Dim command ...
0
9666
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10544
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7788
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6977
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5645
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5821
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4447
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4010
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3111
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.