Rex_C
Rex_C

Reputation: 2477

Dynamic Response.Redirect to previous page

I have a "thank you" page that is shared by two different forms pages. What I want to do is depending on what the original page was, have the Response.Redirect populate the previous page's url after a period of 4 seconds.

I'm not sure how to go about grabbing the previous url to put into the redirect, possibly through reflection? I've gotten this far:

protected void Page_Load(object sender, EventArgs e)
{
    System.Threading.Thread.Sleep(4000);
    Response.Redirect("some sort of dynamic code");
}

Upvotes: 0

Views: 493

Answers (3)

Tim
Tim

Reputation: 4099

You can use the PreviousPage property. This can tell the web form that sent you to the thank-you page. You'll need to add a few settings to the top of the .aspx page in order to set this up.

http://msdn.microsoft.com/en-us/library/system.web.ui.page.previouspage%28v=vs.110%29.aspx

Upvotes: 1

Giannis Grivas
Giannis Grivas

Reputation: 3412

As this one says very analytically : Suggested solutions

there are several ways to accomplish this. In brief:

1) Request.QueryString["SomeParameter"].ToString();

2) this.Context.Items["Parameter"].ToString(); and Server.Transfer("somePage.aspx", true);

3) Posting form to another page instead of PostBack

4) Adding PostBackURL property of control for cross page post back.

Choose your best one and try it.

Upvotes: 0

DLeh
DLeh

Reputation: 24395

You'll want to do this client-side, if you want to show something from the server. You can provide the page you want to direct to via a asp:HiddenField, and then load that value in javascript and redirect.

Something like:

var redirectUrl = document.getElementById("myRedirectUrlHiddenFieldID");
setTimeout(function() { window.location = redirectUrl; }, 4000);

Upvotes: 0

Related Questions