Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirect Issues

Status
Not open for further replies.

elhaix

Programmer
Joined
Jul 31, 2006
Messages
115
Location
CA
I have a C# asp page that needs to record a hit and redirect, but the Javascript isn't executing and the redirect beats the JS execute.

Code:
<head runat="server">
    <title></title>
    <script src="[URL unfurl="true"]http://www.myserver.com/record.php?siteid=215&wayid=922&prodid=recordcode"[/URL] language="JavaScript" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>Redirect</h1>
        <!-- add Client Control Center's tracking pixel -->
        <%
            
            // add Client Control Center's API integration
            try
            {
                codeID = Request.QueryString["code"];

                // could make db call here, but the request may take too long
                // using the existing link may be good, however if CardOffers changes the link, this will break
                Response.Redirect("[URL unfurl="true"]http://www.redirectsite.com/manage/track/e.asp?ID="[/URL] + codeID);

            }
            catch (Exception ex)
            {

            }            
        %>
    </div>
    </form>
</body>

The Javascript needs to execute, and the redirect passes the QueryString parameter to the next page. This page is actually to record the impression.

Is there an alternative way of doing this, or storing the redirect in another event method in the codebehind?
 
You are using an outdated technique which is brought over from classic ASP. Instead of using <% %> code blocks, use the code behind file and the relevant Page Events to execute any code.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Ok, I used the Page_PreRender(object sender, EventArgs e) event, is this the right event, if not, which is it?

Thank you.
 
The page load method is more suited to anything you need to do as the page loads.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Ok, so I want my JS code to execute, and ensure it executes, then redirect... is this right?

Code:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Response.Write("<script src='[URL unfurl="true"]http://www.myserver.net/recording.php?siteid=215&wayid=922&prodid=thecode'[/URL] language='JavaScript' type='text/javascript'></script>");
            // add Client Control Center's API integration
            try
            {
                recordID = Request.QueryString["code"];

                Response.Redirect("[URL unfurl="true"]http://www.redirect.com/manage/track/e.asp?ID="[/URL] + recordID);

            }
            catch (Exception ex)
            {

            }
        }
 
Instead of the response.write use the RegisterStartupScript method. It's a little different depending on what version of the framework your using.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top