CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 4/11/2007 12:51:07 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 7 Views: 33 Favorited: 0 Favorite
8 Items, 1 Pages 1 |< << Go >> >|
LeMerovingian
Asp.Net User
Alternating header Navigation4/11/2007 12:51:07 AM

0

I have a website with a graphics-based navigation scheme.

When the user navigates from one page to the next I need the respective graphical nav link to be a different color and correspond to the page being displayed.

At the moment I am using master pages for the layout, and a user control for the menu structure. Each time the page is loaded I check what page it is and load the correct user control with the pre-selected navigation item.

Is there a better way to do this?
netapostle
Asp.Net User
Re: Alternating header Navigation4/11/2007 5:25:47 AM

0

Hello!

I've tackled a similar situation on the site I'm working on now. I have a site-wide menu at the top of every page, and the menu needs to highlight the current page. For me, this amounts to putting a different css class on the menu link. For you, it sounds like you'll need to use a different image.

The approach I took was to create a user control for the menu. The user control contains a SiteMapDataSource and a Repeater control bound to it. The Repeater's ItemTemplate contains nothing more than a HyperLink control whose properties are bound to the properties of the SiteMap nodes that are returned by the SiteMapDataSource.

<asp:SiteMapDataSource ID="menuSiteMapDataSource" runat="server" ShowStartingNode="false" StartFromCurrentNode="false" StartingNodeOffset="0" />
<asp:Repeater ID="menuLinks" runat="server" DataSourceID="menuSiteMapDataSource">
	<ItemTemplate>
		<asp:HyperLink ID="menuLink" runat="server" NavigateUrl='<%# Eval("Url") %>' Text='<%# Eval("Title") %>' CssClass='<%# GetMenuLinkCssClass((SiteMapNode)Container.DataItem) %>'></asp:HyperLink>
	</ItemTemplate>
</asp:Repeater>

 Note, however, that the CssClass on the HyperLink control is bound to a method call, GetMenuLinkCssClass. This method's job is to determine if the SiteMapNode whose link is currently being built represents the page that is currently being displayed. The method takes a SiteMapNode as its only argument. You can see in the code above that I'm casting the data item that's being bound as a SiteMapNode and passing it into the method.

The GetMenuLinkCssClass method is pretty simple:

protected string GetMenuLinkCssClass(SiteMapNode node)
{
	if (SiteMap.CurrentNode.Equals(node) || SiteMap.CurrentNode.IsDescendantOf(node))
		return "current";
	else
		return "";
}

 It uses the SiteMap api's CurrentNode property (which is a SiteMapNode representing the current page) and compares it with the SiteMapNode that was passed in as a parameter (which represents the current SiteMapNode being used to create a Hyperlink in the menu). If the CurrentNode is equal to the node that is being built in the menu or the CurrentNode is a descendant of the node being built in the menu, the method returns "current", which is the name of the CSS class that is used for the current menu item. Otherwise, it returns an empty string.

I'm thinking that you might be able to employ the same techniques to build a single user control to use for your menu, rather than using a different user control for each page.

Hope that helps!

LeMerovingian
Asp.Net User
Re: Alternating header Navigation4/11/2007 6:22:33 AM

0

Hi Netapostle,

thanks for your suggestions. I think your solution would work great for text/css-based navigation but I am not sure if it would help in my situation with graphical link items, as I have two images for each link (one active, and one inactive). To complicate things further each link item may be related to multiple pages, ie the "Shop" link item will remain active for all pages related to shopping (it is a major header).
 

netapostle
Asp.Net User
Re: Alternating header Navigation4/11/2007 9:49:26 PM

0

Hello,

I think your situation would be a bit more difficult than mine, but you could probably make it work. Instead of having a method that returns to you a css class, you could have a method that returns to you the url of the image that should be shown. You could keep a collection of active image paths and inactive image paths in the codebehind for the user control. That way the images are configured in only one place.

All of the assumes, though, that you're using a SiteMap of some sort. If you are, then the SiteMapNode.IsDescendantOf method is very useful to determine if the node for the current page is a child (or grandchild or great-grandchild, etc) of another. Using this method will allow you to determine if your on a page in the shopping section, and if so, to show the active shopping menu item graphic instead of the inactive one.

The code example I put in my earlier post did just that. It checks to see if the current page's SiteMapNode is a descendant of the menu node that's currently being built. If so, it returns "current." In this way, the top-level menu item is highlighted on both the top-level page for that menu item and all pages in that section.

Anyway, I hope you are able to make a go of it!

netapostle

LeMerovingian
Asp.Net User
Re: Alternating header Navigation4/12/2007 3:22:19 AM

0

hi netapostle.

that makes sense. i'll give it a go.

thanks
 

LeMerovingian
Asp.Net User
Re: Alternating header Navigation4/12/2007 8:00:58 AM

0

netapostle,

i rolled a solution using your suggestion. it works great.

thanks for the fresh outlook on the problem. the beauty of this is now i can also use the sitemap for my breadcrumb navigation.

cheers

 

netapostle
Asp.Net User
Re: Alternating header Navigation4/13/2007 7:17:20 PM

0

Awesome! I'm glad you were able to make it work. I've had good success with it so far, too, and I'm glad it was able to benefit you too!
image619
Asp.Net User
Re: Alternating header Navigation4/17/2007 11:39:33 PM

0

Thank you netapostle! This is exactly what I've been searching for!

-image

8 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Advanced SharePoint services solutions Authors: Scot Hillier, Pages: 365, Published: 2005
CSS, DHTML, & Ajax: Visual QuickStart Guide Authors: Jason Cranford Teague, Pages: 562, Published: 2007
Microsoft Office 2007 in Depth Authors: Ed Bott, Woody Leonhard, Pages: 1056, Published: 2008
Professional ASP.NET 2.0 Design: CSS, Themes, and Master Pages Authors: Jacob J. Sanford, Pages: 474, Published: 2007

Web:
Alternating header Navigation - ASP.NET Forums I have a website with a graphics-based navigation scheme. When the user navigates from one page to the next I need the respective graphical ...
Alternating Flash Header on Refresh Script not working in Firefox ... I have the following script which will load a random flash header when a ... A well designed So file will let you do everything you need to do from alternate based on views, .... Site Navigation: v7n Home .::. Graphics .::. Scripts .::. ...
Header Image Module - Joomla! Extensions Directory The excellent rating is for the alternate headers option. ... I use graphical navigation with my header image via a usemap, and by selecting the: ...
Alternating Page Numbers I also want to alternate the page numbers in the header s. ... Now click the Next Section button in the Navigation group to get to the Even ...
OK Great » Blog Archive » Website Build Report: Inspire ... All shared the alternating color bands of grey, blue, white, blue, grey. ... and the templates breaking down cleanly into a header, navigation, and footer. ...


Videos:
Nvu: Multimedia Application: Nvu - Adding multimedia components to web pages.
Nvu: Multimedia Application: Nvu - Adding multimedia components to web pages.
Nvu: Multimedia Application: Nvu - Adding multimedia components to web pages.
Nvu: Multimedia Application: Nvu - Adding multimedia components to web pages.
Nvu: Multimedia Application: Nvu - Adding multimedia components to web pages.






control within master page gets "does not exist in the current context"

disable wizard navigation button in templatedwizardstep

ms crm / outlook web. statically positioned, dynamic menu selection. how is this done?

theme repository?

menu control w/web.sitemap

headerstyle problems

i've been looking at this for too long - menu issue

creating a expandable menu with treeview

menu problems with appearing under master page content

switching master page css theme programmatically

treeview target=_blank

compiler error message: bc30456: 'theme' is not a member of 'asp.index_aspx'.

how to programm dynamic navigation with submenus like in cms. is there a webcontrol for it?

localize navigationurl of asp:hyperlink

asp.net menu control

please help...

master page cart update

getelementbyid gets wrong id?

capturing button_click event from master page

viewstate not saved on master page

loading items in a menu instance from an xml file

problem with treeview expand for current page

using web.sitemap to generate "next" and "previous" links

specify which sitemap to take for the sitemappath

sitemap - cannot get it to display

are masterpages stable?

dynamically load website.map file based on active directory group

problem with treeview's checkednodes not being set correctly

user can decide beteween two different styles (css .skin etc)

hi, i have a problem with stylesheets, can you please help me?

   
  Privacy | Contact Us
All Times Are GMT