Open a new window from C# code

I support a website for a non-profit theatre group in Atlanta at  When a visitor wants to buy tickets, I open a new window with an SSL connection to my ticketing app; all works fine.

My new task is to allow users the option of entering a promo code on the Buy Tickets page to receive a discount ticket price.  My current thought is to do something like the following (see for a partial implementation):

      If you have a promo code, enter it and click 'Go':
  _______________________   <GO>
  Purchase season tickets
  Purchase tickets for My Name is Rachel Corrie


The "Purchase season tickets" link is created using:
<a href=
onClick=", '','toolbar=yes,location=no-directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=640,height=600');return false;">Purchase season tickets </a>

The "Promo code" text box and button are created using:
<asp:TextBox ID="txtPromo" runat="server"></asp:TextBox>
<asp:ImageButton ID="btnGo" runat="server" ImageUrl="../images/go.gif" AlternateText="Submit Promo Code" OnClick="btnGo_Click" />

In the "btnGo_Click" code, I verify that the promo code is valid.  If valid, I capture the promo code, user and time.  I then want to generate in code a link similar to the "Purchase season tickets" link shown above and perform a click to open the buy reduced price tickets window.

How do I do this in my btnGo_Click (C#) code?  After the user enters a valid promo code and clicks go, the code should automatically open the new SSL buy reduced price tickets window.  The effect should be execution of the following link:
<a href=
onClick=", '','toolbar=yes,location=no-directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=640,height=600');return false;">Purchase reduced price tickets </a>



8/13/2007 4:55:30 PM 93655 articles. 6 followers. Follow

5 Replies

Similar Articles

[PageSpeed] 22
Get it on Google Play
Get it on Apple App Store

Once you verify the promo code, user ClientScript.RegisterStartUpScript to open the window. This will render the javascript when the server responds to your requested postback. Not sure if you want to add support for users who aren't javascript enabled though, might need to keep this info present in the url, and send them to a wizard step like page as an altenative.

8/13/2007 5:04:14 PM

OK... I have a pretty limited understand of JavaScript and integrating it with the ASP.NET 2.0 page model.

I think I need to start with something like this:

protected override void OnPreRender(EventArgs e)
Page.ClientScript.RegisterStartupScript(typeof(Page), "promo", "'', '','toolbar=yes,location=no-directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=640,height=600');return false;");

(Do I need the base.OnPreRender(e); statement?)

What statement do I add to my C# code to call the above JavaScript (assuming it is correct)?


8/13/2007 6:42:30 PM

 You can do it on Page_Load. It is good practice to let the PreRender run the base(e),  in this scenario it wont make a difference whether or not it is there.

The code is registered as startup script, it will run immediately on window load. 

8/13/2007 8:11:45 PM

I apologize - I need a very basic instruction on exactly how to call the JavaScript that I have defined above in the RegisterStartupScript statement with the key "promo" (assuming that this is the code I need). 

Note that the script should only be called if the user enters a promo code and clicks the 'Go' button.  So, I need to call the script in the BtnGo_Click routine after I verify that the promo code is valid and capture the promo code data.  However, I'm not sure how to call the script from the C# code.

Do I need to add additional code into the RegisterStartupScript to incorporate the within a JS function?  Then place a call to that function from the C# code?  If so, how?

I understand that what I'm asking is very basic - but perhaps because it is so basic, none of my reference material gives an example of how to accomplish this.

I appreciate all of your help!

8/13/2007 9:03:18 PM

No, stop thinking (LOL) and just put RegisterStartUpScript with your javascript code in your button click event.  When the button is clicked the code will be rendered to the page, and the javascript will automatically run.


8/13/2007 9:44:01 PM

Similar Artilces:

Entering data in old aspx form only after saving data in new web form opened in new window
Dear all, i am facing a problem. please solve it. i have created two .aspx pages, say, page1.aspx and page2.aspx. with the help of client-side javascript i am opening page2.aspx from page1.aspx in a new window. So, page1.aspx and page2.aspx remains open at the same time. what i want is, i don't want the user to able to activate or enter data in page1.aspx without saving data in page2.aspx. regards subhajit use window.showModalDialog() instead of when the child window is closed, in this case, program execution continues on the next line after the showModalDialog...

How to open a new web form in a new window?
How to open a new web form in a new window when we click on a button? Ex: I Have a Webform1.aspx which has a button and a few other controls. When click on the button i need to open a small window with Webform2.aspx which has a few other controls, the user enters the data and clicks on ok when we need to save and close webform2 and go back to webform1.aspx. How to do this? Any suggestions will be appreciated. Thanks. Check out these articles: Darrell Norton, M...

how to change these windows form code to web form code?
hi, i'm a beginner of c#,i want to know how to change these windows form code to web form code //////////// private void buttonSign_Click( object sender, System.EventArgs e) { //get original message as byte array byte[] messagebytes = Encoding.UTF8.GetBytes( textOriginalMessage.Text); //create digest of original message using SHA1 SHA1 sha1 = new SHA1CryptoServiceProvider(); byte[] hashbytes = sha1.ComputeHash(messagebytes); //display hash bytes in hex format StringBuilder sb = new StringBuilder(); for (...

Open a web form in a new window
Hi everyone, I am using  Responde.Redirect(url) to to move from one page to another. I would like to open the new page in a new window. How can I do that?Any help will be very appreciate. Thank you Response.Redirect is a serverside method call. Opening things in a new window is a client side thing. So no, you cannot do this from your serverside code. You'd have to use the Javascript method. Or specify the TARGET attribute in your link. Cheers, Wim Wim Hollebrandse--- Thanks but I do not want to use Jscript and I dont use Hyperlinks,...

How to open web form in new window ?
How to open web form in new window ? Check my Blog below, I have an article on how to open a new window in using javascript. regards.Bilal Hadiar, MCP, MCTS, MCPD, MCTMicrosoft MVP - Telerik MVP window.Open using javascript, or if you have a hyperlink, set the target to _blank.Brian"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4). Hi, you need to check this post : view post 818881 regardsBilal Hadiar, MCP, MCTS, MCPD, MCTMicrosoft MVP - Telerik M...

Open web form in new window
I want to know how to open web form in new browser window from a web form using server side code because i want to pass some data using query string in that new window form.   Thanks Parshant kalia   You can't open a window from server-side code, but you can drop client-side code from server-side that will open a new window.  Think Check following sample and modify it according to your requirement     Public Sub ShowPopupWindow()        Try        &n...

VB.NET Code to open a new window
Hello,I want a new page to open up, call downloadfile, the close the page again.  how do I do that? I have a timer1_Tick going on, once a file exists, it will open a new page, call the download, and close again. On the parent page open a new window using javascript  Call the below function on the link <a href = '#' onclick = "popUp()" >DownLoadFile</a>var Popup;function popUp() { Popup ="DownLoad.aspx", "Popup", 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=420,height=300,le...

Force a new browser window to be opened from a web form ?
Does anyone know how to force a new browser window to be opened from a web form following Response.BinaryWrite or Response.Write if the data to be displayed is html? Html data is diplayed in the current browser but for non html data the appropriate application is opened e.g. ms-word, excel etc. Effectively, I want html to be treated just like the other mime types.ThanksMajella Majella,Since at the server-end you are going to set the contentType and start streaming the content, you can set a window open to an ASPX Page and in that page (or the same page with a different QueryString Pa...

Using C# code behind to open a new Internet Explorer window
I'm using the Response object to stream pdf document to the browser when a user hits a particular button on a page. This is working correctly, however the pdf opens in the same browser window. How do I open a new (second) browser window and stream the output to this new window? Thanks! You have to use client side code (javascript) to open a new IE window. You can call the javascript after server side code executed.This posting is provided "AS IS" with no warranties, and confers no rights. Hi, first check out this code sample: Open a popup window after a button click After reading you...

Open Web Form Using Server.Transfer in New Explorer Window
Hi, I have a requirement to open the form as MODAL using Server.Transfer. It should be opened in New Explorer Windows Any Idea? Regards Atif     hi, I think you had better use javascript window.showModalDialog, cause Server.Transfer cannot open a new window. Hi, Thanks for prompt response. I know how to open the MODAL FORM using Javascript.  If I want to pass let say one variable to Child Form. How do i do this ? ... this variable is transaction id and shouldn't be part of the HTTP Query (Confidential). How can do this ?     ...

windows forms in vb .net into web forms
we are creating a database driven website as part of our project. currently we have forms connecting to the database created in visual basic. these windows forms we need to convert into web forms which are asp .net compatible. can u give me an answer or show me a way. Hi, because of the difference in nature between web and win applications you'll need to reimplement at least the UI part. If you have a multitiered application in which the busines logic and data access are in different parts/assemblies you can reuse them. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Wor...

Open a new window with
Hi, =20 in our web application, we try to open a popup-window with But instead of opening a new window, a new tab is opened. =20 In the SeaMonkey preferences, we configured it, to open new links in a new tab. With firefox, we had the same preferences, but when was called, a new window was opened.=20 How can we configure SeaMonkey, so that it has the Firefox behavior when calling ? =20 Thanks in advance. =20 =20 =20 Artur Zeiler schrieb: > Hi, > > in our web application, we try to open a popup-window wi...

opening new window other than
is there any other way of opening a new window... aside from has a memory leak so i want to prevent using it as much as possible.Alvin ShihSoftware DeveloperMCP MCTS MCPD Hi window.showmodaldialog() but supports only IE....   Regards Suresh Kumar Goudampally Why dont you avoid pop up windows all together and use an iframe that is positioned over the content? Eric | Twitter epascarello | LinkedIn Hi,Try Target="_blank" N.P.SenthilSoftware Engineer  Link buttons targer property is set to "_blank"...

superreview granted: [Bug 172962] Options for where to open URLs from other applications (reuse tab, new tab, new window) : [Attachment 159442] base code to control where URLs are opened
Peter Van der Beken <> has granted Dan M <>'s request for superreview: Bug 172962: Options for where to open URLs from other applications (reuse tab, new tab, new window) Attachment 159442: base code to control where URLs are opened ------- Additional Comments from Peter Van der Beken <> What biesi said, plus > Index: docshell/base/nsDocShell.cpp > ===================...

Web resources about - Open a new window from C# code -

Window - Wikipedia, the free encyclopedia
This article is about the part of a building. For the Microsoft operating system, see Microsoft Windows . For other uses, see Window (disambiguation) ...

Microsoft Windows Information, Solutions, Tools - Windows IT Pro
Microsoft Windows information and solutions for IT pros. Topics include cloud computing, Windows Server, Exchange, Outlook, PowerShell, virtualization, ...

The Windows Blog
The Windows Blog is Microsoft's Official Blog for the Windows Operating System.

Lumia 950 review: Windows Phone finally has a new flagship—will anyone care?
Lumia 950 (credit: Peter Bright) Specs at a glance: Microsoft Lumia 950 Screen 2560×1440 5.2" (564ppi) AMOLED OS Windows 10 Mobile 10586 ...

Get amazing music, games, movies, and apps for only ten cents each on Windows 10
Windows 10 is arguably a success. True, not everyone loves it, but many according to Microsoft have downloaded it. A huge benefit of having large ...

How to remove ads from the Start menu on your Windows 10 computer
There are plenty of issues with Windows 10 , from privacy concerns to incompatible software, but nothing has been quite as galling to me as the ...

Watch Steve Ballmer go nuts in the first Microsoft Windows ad from 1986
Today, November 20th, is the 30th birthday of Microsoft Windows 1.0, the operating system that sparked a PC revolution . Which also means that ...

Windows turns 30
From Windows to "Back to the Future" to "Calvin and Hobbes," here's what made a cultural impact in 1985

CNET UK podcast 458: Windows turns 30, Sky's Q box and Black Friday blues
We discuss Sky's fancy new premium TV service Sky Q, wish Windows a happy 30th birthday and debate whether the UK is sick of Black Friday riots. ...

Microsoft Lumia 950: The first Windows 10 smartphone tries hard but can it succeed?
Microsoft's new Lumia 950 , the first phone to use Windows 10, is in many ways a very old-fashioned phone. It doesn't have the high-end metallic ...

Resources last updated: 11/22/2015 5:27:02 PM