I had a very interesting E-Mail exchange with Exo_duz, referring his post from June 2006 about the problem "setting id for menu adapter and output it in the li tags".
I wrote to him:
It was very interesting for me to read about your problem and I think that could be a fine solution. But how can you go further after processing individual IDs for the li tag. Where can they be built in? I tried to get them in the MenuStyle.css but it wasn't
succesfull. Could You give me an advice? Thanks Thomas
He answered:
I’ve actually changed the code now instead of a page + number (page1, page2, etc) I’ve used another method because the id had to be unique
and the page number will stuff up if I add another page in between other nodes in the web.sitemap file. Look at the following code:
//get the description of the url and create unique page id
//change to lower-case, remove spaces and get the first 6 letters
string
page_id = item.Text;
page_id = page_id.Trim();
page_id = page_id.ToLower();
page_id = page_id.Replace(" ",
"");
if
(page_id.Length > 13)
{
page_id = page_id.Substring(0, 12);
}
writer.WriteAttribute("id", page_id);
This will remove all whitespaces and convert to lower case. Then if the “title” is more than 12 characters it just truncates it.
Why I’m doing this you ask? This is more for CSS issues. I did this as it was neater to set header tags, div tags and CSS related issues if I needed to change anything
with the styling of the page.
The output of the above code would be, note the id tags that I’ve marked in red:
<li class="AspNet-Menu-Leaf"id="directorsand">
<a href="/CI/directors_management.aspx" class="AspNet-Menu-Link" title="Directors and Management">Directors and Management</a>
This will then target the h1 tags in the page
“directors_management.aspx”.
If you would like to see an example of this, let me know and I’ll gladly
let you know the URL of the site I use this method on.
Hope this helps. Can you post this question to the forums and I’ll put
this reply on there for you? Just in case someone else needs to use this method.
publicocean1
Member
10 Points
2 Posts
setting id for menu adapter and output it in the li tags from exo_duz
Aug 11, 2006 07:41 AM|LINK
Hi together,
I had a very interesting E-Mail exchange with Exo_duz, referring his post from June 2006 about the problem "setting id for menu adapter and output it in the li tags".
I wrote to him:
It was very interesting for me to read about your problem and I think that could be a fine solution. But how can you go further after processing individual IDs for the li tag. Where can they be built in? I tried to get them in the MenuStyle.css but it wasn't succesfull. Could You give me an advice? Thanks Thomas
He answered:
I’ve actually changed the code now instead of a page + number (page1, page2, etc) I’ve used another method because the id had to be unique and the page number will stuff up if I add another page in between other nodes in the web.sitemap file. Look at the following code:
//get the description of the url and create unique page id
//change to lower-case, remove spaces and get the first 6 letters
string page_id = item.Text;
page_id = page_id.Trim();
page_id = page_id.ToLower();
page_id = page_id.Replace(" ", "");
if (page_id.Length > 13)
{
page_id = page_id.Substring(0, 12);
}
writer.WriteAttribute("id", page_id);
This will remove all whitespaces and convert to lower case. Then if the “title” is more than 12 characters it just truncates it.
Why I’m doing this you ask? This is more for CSS issues. I did this as it was neater to set header tags, div tags and CSS related issues if I needed to change anything with the styling of the page.
The output of the above code would be, note the id tags that I’ve marked in red:
<li class="AspNet-Menu-Leaf" id="directorsand"><a href="/CI/directors_management.aspx" class="AspNet-Menu-Link" title="Directors and Management">Directors and Management</a></li>This means that I can in the CSS:
.directorsand h1 {
background-color: #fff;
background: url(../images/text/h1-directorsand.gif) no-repeat;
height: 18px;
}
Note that I’m using Master Pages and thanks to information I got from this page:
http://www.odetocode.com/Articles/450.aspx
In the master pages I make a publicly accessible variable:
//set the container css class of the master page
public string Container_Class
{
get
{
return container.CssClass;
}
set
{
container.CssClass = value;
}
}
The above variable is then accessed from the content page like this:
protected void Page_Load(xobject sender, EventArgs e)
{
if (!IsPostBack)
{
Master.Container_Class = "directorsand";
}
}
This will then target the h1 tags in the page “directors_management.aspx”.
If you would like to see an example of this, let me know and I’ll gladly let you know the URL of the site I use this method on.
Hope this helps. Can you post this question to the forums and I’ll put this reply on there for you? Just in case someone else needs to use this method.
It would be great to the see the example.
Thomas