By:Mark Angeletti, Published:2005-1-15

Now that we have our breadcrumb class we will look at adding it to our web page(s).

We are going to use an ASP.NET User control (.ascx) so that we may simply add this control to our pages making it easy to maintain and modify later if we should choose to. For example, if we have 100 pages and we want to modify the separator in our breadcrumb navigation from the “>” symbol to an image we will only have to modify 1 page, our .ascx page and not all 100 .aspx pages.

The .ascx Page Code:

  1. <%@ Register TagPrefix="bc" Namespace="BreadCrumbs" Assembly="BreadCrumbs" %>
  1. <bc:ctrlBreadCrumbs id="bc1" runat="server" />

The Code Behind For The .ascx Page:

  1. protected BreadCrumbs.ctrlBreadCrumbs bc1;
  2.  
  3. private string _strHeaderText;
  4. public string HeaderText
  5. {
  6.   get
  7.   {
  8.    return _strHeaderText;
  9.   }
  10.   set
  11.   {
  12.    _strHeaderText = value;
  13.   }
  14. }
  15.  
  16. private void Page_Load(object sender, System.EventArgs e)
  17. {
  18.   // Put user code to initialize the page here
  19.   bc1.PageTitle = HeaderText;
  20. }

Creating Our Web Pages (.aspx)

For each page (.aspx) you create for your website use a literal for the <title>. Like this:

  1. <title><asp:literal id="lblPageTitle" runat="server" /></title>

This allows us to define the actual title for our page in the code behind. By defining the title of the page in the code behind we gain the benefit of only having to assign it once and have it not only be used for the title of our page, but also be used in our breadcrumb navigation.

Your code behind would look like this:

  1. public class CodeBehind_for_page: System.Web.UI.Page
  2. {
  3.   protected System.Web.UI.WebControls.Literal lblPageTitle;
  4.   protected NameSpace.headerBreadCrumb header;
  5.  
  6.   private void Page_Load(object sender, System.EventArgs e)
  7.   {
  8.    // Put user code to initialize the page here
  9.    string PageTitle = "ASP.NET Breadcrumbs with C#";
  10.    lblPageTitle.Text = PageTitle;
  11.    header.HeaderText = PageTitle;
  12.   }
  13. }

Conclusion:

We created a class for our breadcrumb navigation and used that class for an ASP.NET User control (.aspx). This allows us to simply drop the User control into each web page (.aspx) we create. Once we have our User control in our page we assign the PageTitle in the code behind and this gets used for the <title> as well as the breadcrumb control.

mulberry sale spyder womens jacket cheap new balance 574 mulberry outlet cheap new balance 574 arcteryx outlet mulberry sale spyder womens jacket mulberry sale spyder womens jacket mulberry outlet mulberry outlet new balance 574

Popular Articles

Top 10 Commentators


Subscribe to this feed! Subscribe by Email!

Random Bits Podcast

You need to download the Flash player from Adobe

Other Sites