I support a website for a non-profit theatre group in Atlanta at www.synchrotheatre.com. 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 http://test.synchrotheatre.com/tickets/buytickets.aspx for a partial implementation):
|If you have a promo code, enter it and click 'Go':|
|Purchase season tickets|
|Purchase tickets for My Name is Rachel Corrie|
The "Purchase season tickets" link is created using:
onClick="window.open(this.href, '','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:
onClick="window.open(this.href, '','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>
I think I need to start with something like this:protected override void OnPreRender(EventArgs e)
Page.ClientScript.RegisterStartupScript(typeof(Page), "promo", "window.open('https://cp.newtechwebservices.com/ssl/synchronicity/secure/buypromo.aspx', '','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?)
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.
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 window.open 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!