hi
i am using asp.net with c#
i want to know how to creat bread crumbs for dynamically created pages
(i dont want to use site map because i think site map is only for static pages)
do help me in this regard
looking forward for a positive reply to the earliest :)
2 3914
Hi there,
i have attached some sample code segment below.. hope it helps you to get started.. take care..
the code.. -
using System;
-
using System.Web.UI;
-
using System.Web.UI.WebControls;
-
using System.ComponentModel;
-
using System.Text;
-
// We include the System.Text namespace so we can use the StringBuilder object later.
-
namespace BreadCrumbs
-
{
-
/// <summary>
-
/// Summary description for ctrlBreadCrumbs.
-
/// </summary>
-
public class ctrlBreadCrumbs : System.Web.UI.WebControls.WebControl
-
{
-
/// <summary>
-
/// The 3 variables below, Separator, RootName, directoryNameSpacer can be changed to meet your needs
-
/// PageTitle is pulled from the CodeBehind of the page
-
/// </summary>
-
public string Separator = " > ";
-
public string RootName = "Home Page";
-
public char directoryNameSpacer = '_';
-
private string _PageTitle;
-
-
// Above are our variables that we can set:
-
// Separator is the ‘>’ symbol
-
// RootName is the homepage anchor text
-
// directoryNameSpacer is the naming scheme for my directories, for example: search_engine_optimization or website_design (notice the URL in the address bar above)
-
-
-
public string PageTitle
-
{
-
get
-
{
-
return _PageTitle;
-
}
-
set
-
{
-
_PageTitle = value;
-
}
-
}
-
/// <summary>
-
/// Render this control to the output parameter specified.
-
/// </summary>
-
/// <param name="output"> The HTML writer to write out to </param>
-
protected override void Render(HtmlTextWriter output)
-
{
-
StringBuilder sbResult = new StringBuilder();
-
// sbResult StringBuilder will hold the breadcrumb navigation when done
-
-
// get the url root, like www.domain.com
-
string strDomain = Page.Request.ServerVariables["HTTP_HOST"].ToString();
-
strDomain.Trim(); // Trim removes leading and trailing whitespace
-
sbResult.Append ( "<a href='http://" + strDomain + "'>" + RootName + "</a>" + Separator );
-
-
// gets dir(s), like subdirectory/subsubdirectory/file.aspx
-
string scriptName = Page.Request.ServerVariables["SCRIPT_NAME"].ToString();
-
// find the last '/' and Remove the text after it as it's the file name
-
int lastSlash = scriptName.LastIndexOf('/'); // returns the # of chars. from right to /
-
string pathOnly = scriptName.Remove(lastSlash, (scriptName.Length - lastSlash));
-
-
// create breadcrumb HTML for the directory name(s)
-
// We Remove the first "/" otherwise when you split the string the first item in array is empty
-
pathOnly = pathOnly.Substring(1);
-
string[] strDirs = pathOnly.Split('/');
-
int nNumDirs = strDirs.Length;
-
-
// URLs for breadcrumbs
-
string strURL = "";
-
for (int i=0; i<nNumDirs; i++)
-
{
-
strURL += "/"+strDirs[i];
-
-
// convert underscores to spaces
-
strDirs[i] = strDirs[i].Replace(directoryNameSpacer,' ');
-
-
int counter = i+1;
-
if (counter != nNumDirs)
-
{
-
sbResult.Append ( "<a href='http://" + strDomain + strURL + "'>" + strDirs[i] + "</a>" + Separator );
-
}
-
else
-
{
-
// This is the last directory so don't tack on Separator
-
sbResult.Append ( "<a href='http://" + strDomain + strURL + "'>" + strDirs[i] + "</a>" ); }
-
}
-
// write the PageTitle, pulled from the CodeBehind!
-
sbResult.Append ( " : " + this.PageTitle );
-
-
output.Write ( sbResult.ToString() );
-
-
}
-
}
-
}
-
The .ascx Page Code: -
<%@ Register TagPrefix="bc" Namespace="BreadCrumbs" Assembly="BreadCrumbs" %>
-
-
<bc:ctrlBreadCrumbs id="bc1" runat="server" />
-
The Code Behind For The .ascx Page: -
protected BreadCrumbs.ctrlBreadCrumbs bc1;
-
-
private string _strHeaderText;
-
public string HeaderText
-
{
-
get
-
{
-
return _strHeaderText;
-
}
-
set
-
{
-
_strHeaderText = value;
-
}
-
}
-
-
private void Page_Load(object sender, System.EventArgs e)
-
{
-
// Put user code to initialize the page here
-
bc1.PageTitle = HeaderText;
-
}
-
Creating Our Web Pages (.aspx) -
<title><asp:literal id="lblPageTitle" runat="server" /></title>
-
Your code behind would look like this: -
public class CodeBehind_for_page: System.Web.UI.Page
-
{
-
protected System.Web.UI.WebControls.Literal lblPageTitle;
-
protected NameSpace.headerBreadCrumb header;
-
-
private void Page_Load(object sender, System.EventArgs e)
-
{
-
// Put user code to initialize the page here
-
string PageTitle = "ASP.NET Breadcrumbs with C#";
-
lblPageTitle.Text = PageTitle;
-
header.HeaderText = PageTitle;
-
}
-
}
-
Hi Sashi
I've been trying to get the code you posted working, but can't in Web Matrix, Dreamweaver or Visual Studio. Could you send me the individual files which should be created from this code or post working examples including all the HTML in each page. pac303@yahoo.co.uk
Thanks in advance, Paul.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Robert Guildner |
last post by:
I am new to JavaScript and I am building a Web page in which I want to use a
navigational/informational feature that I have seen called bread crumbs. It
looks like: home>>one level>>next...
|
by: Irshad |
last post by:
Hi Al
If anyone has worked with Bread Crumb or have Knowledge on that.Please I Need some samples of creating Bread Crumb in .NET
Please let me know ASAP
Thank
-Irshad
|
by: gb |
last post by:
Within a form, the usual way of submitting it is to use e.g.
<INPUT TYPE="submit" VALUE="Send ">
This produces the standard button. Is there an easy way to portray this as
though it were a...
|
by: Boris Ammerlaan |
last post by:
About once a week, I post an FAQ pointer in this newsgroup
under the same heading as this post. That pointer has two purposes:
1. To keep regulars from having to post the standard answers to...
|
by: -=Chris=- |
last post by:
Hello all,
I've designed a custom bread crumb control for several of my asp.net
projects. The default property of this control is a custom
HyperLinkCollection I've created, which contains, you...
|
by: Eric Lindsay |
last post by:
I have been trying to do a CSS liquid layout imitating a frame, using
position: fixed for header, footer, and side navigation, and a fixed
background image. Page is valid HTML 4.01 Strict, and is...
|
by: Piotr Nowak |
last post by:
Hi,
Is there any bread crumbs component like this
http://geekswithblogs.net/azamsharp/archive/2006/08/16/88197.aspx for
asp.net 1.1 ?
I need to show my users place where they are at any...
|
by: AAaron123 |
last post by:
Is there a method of making a sitemapnode not visible and still have it's
title appear in the bread crumbs?
The reason for the invisible sitemapnode is so the page appears in the
breadcrumbs (even...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |