简体   繁体   中英

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");
}

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

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);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM