views:

94

answers:

2

Can this be done without MVC? Is there an easy way to abstract or encapsulate navigational logic?

I currently have quite a lot of the following in my code behinds (and I know it's probably not the best thing to be doing):

protected void btnNext_Click(object sender, EventArgs e)
{
   ...

   if (condition1)
   {  Response.Redirect("~/NextPage.aspx");  }
   else if (condition2)
   {  Response.Redirect("~/AnotherPage.aspx");  }
   else
   {  Response.Redirect("~/GoBackToOldKentRoad.aspx");  } 
}
+2  A: 

You may want to consider using the Web.sitemap file to hold your navigation information.

You could also look into the Routing library that was built for MVC in one of the previews, they split those classes off into the System.Web.Routing namespace and from what I've heard, it can be used with WebForms now. I'm not sure how easy it is to use with WebForms yet, but it might be worth looking into.

Andrew Van Slaars
+1  A: 

Based on your example, I don't think that MVC makes much difference. That's pretty much the standard way to do multi-page workflows. MVC would just send it to a different view, presumably, but the underlying concept is the same. Unless you have a very large and complex workflow, that's the simplest way to handle it.

Jeromy Irvine