开发者

pick url of previous before page

开发者 https://www.devze.com 2023-02-19 01:55 出处:网络
I have three pages,..say Page1, Page2, Page3. User clicks a link in Page1 and redirects to Page2 fills a form and sumit which redirect开发者_Python百科s to page3(Thankyou.aspx)

I have three pages,..say Page1, Page2, Page3.

User clicks a link in Page1 and redirects to Page2 fills a form and sumit which redirect开发者_Python百科s to page3(Thankyou.aspx)

I want to place a OK button in Page3 which should redirect to Page1.

I can't hard code it bcoz it should be dynamic

Note: Page1 can be any other page , Page 2 can be any other form but in Page3 i want to track the 1st page from where the process is done.

I know something like :

HttpContext.Current.Request.UrlReferrer

But it gives you the previous page but not the first page.

Can it be achievable.

Thanks in advance


You can also do this with javascript if you want to. You can hook it directly on your Ok button like this:

btnOk.Attributes.Add("onClick", "javascript:history.go(-2); return false;");

or you can register it on your page using a ClientScriptManager (from MSDN):

    // Define the name and type of the client scripts on the page.
    String csname = "GoBackScript";
    Type cstype = this.GetType();          

    // Get a ClientScriptManager reference from the Page class.
    ClientScriptManager cs = Page.ClientScript;

    // Check to see if the startup script is already registered.
    if (!cs.IsStartupScriptRegistered(cstype, csname))
    {
        String scriptText= "<script type=\"text/javascript\">" +
               "window.history.go(-2);</" + "script>";     
        cs.RegisterStartupScript(cstype , csname, scriptText);
    }


The simplest way would be to store the page1 url in the user's session cache

Session["page1"] = HttpContext.Current.Request.UrlReferrer

Then when you get to page3 you have access to it. Make sure that after you use it, you remove it from the session cache, to make sure that you never get any old urls.

0

精彩评论

暂无评论...
验证码 换一张
取 消