0
votes

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

User clicks a link in Page1 and redirects to Page2 fills a form and sumit which redirects 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

2
don't you want to use WizardControl?Robert
I guess the reason not to use a wizard is because of the dynamic nature of what pages are used. Although I agree, that a good design might use a wizard control with dynamically loaded forms in the shape of UserControls.Daniel Dyson

2 Answers

1
votes

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.

1
votes

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