What's the best way to code navigation logic in ASP.NET?

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

In my code, I currently have quite a lot of the following content (and I know this is probably not the best):

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

      

0


source to share


2 answers


You may want to use a Web.sitemap file to store navigation information.



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

+2


source


Based on your example, I don't think MVC matters much. This is a fairly standard way of doing multi-page workflows. Apparently MVC will just send it to a different view, but the basic concept will be the same. If your workflow is not very large and complex, this is the easiest way to handle it.



+1


source







All Articles