Richard Ev
Richard Ev

Reputation: 54127

Managing page sequence

In an ASP.NET 3.5 site we have a relatively standard payment checkout progess that contains a number of pages that need to be visited in sequence (shopping basket, payment details etc)

Each page has a "Continue" button that redirects to the next page in the sequence.

I would like a way of managing the page sequence so that:

  1. I can have a Master page that defines the "Continue" button and its code-behind OnClick event handler
  2. If the user attempts to visit a page out of sequence (by typing the URL directly into their browser, for example) they get redirected to the correct page
  3. This page sequence is nicely defined in one place in my code (in an enum for example)

Upvotes: 2

Views: 185

Answers (2)

IrishChieftain
IrishChieftain

Reputation: 15253

Check the HttpRequest.UrlReferrer variable in each Page_Load method...

http://msdn.microsoft.com/en-us/library/system.web.httprequest.urlreferrer.aspx

... and don't forget to check for nulls! You can bounce them to where they are supposed to be, based on where they came from.

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        Session["PreviousPage"] = Request.UrlReferrer.ToString();
        ...
    }
    else
    {
        ...
    }
} 

Upvotes: 1

PhilPursglove
PhilPursglove

Reputation: 12589

Why not use the ASP.NET Wizard control?

Alternatively (and I haven't tried it so I can't say how well it works), you could use Windows Workflow to define a sequential workflow and let that control the order pages come up in. There's an article at http://www.devx.com/dotnet/Article/34732 that takes you through doing it this way.

Upvotes: 4

Related Questions