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': | |
_______________________ <GO> | |
Purchase season tickets | |
Purchase tickets for My Name is Rachel Corrie |
The "Purchase season tickets" link is created using:
<a href=https://cp.newtechwebservices.com/ssl/synchronicity/secure/buyseason.aspx
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:
<a href=https://cp.newtechwebservices.com/ssl/synchronicity/secure/buypromo.aspx
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>
![]() |
0 |
![]() |
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.
![]() |
0 |
![]() |
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", "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;");
base.OnPreRender(e);
}(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)?
![]() |
0 |
![]() |
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.
![]() |
0 |
![]() |
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 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!
![]() |
0 |
![]() |
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.
ClientScript.RegisterStartUpScript(Page.GetType(),null,"window.onload(etc..)",true);
![]() |
0 |
![]() |