views:

1487

answers:

1

I have an ascx component, that holds two-level menu, because there are several user types, and the menu needs to be computed on server.

Anyways - I'm also doing the highlighting of current menu item on server (adding a selected class/css to an item). Highlighting with javascript is not good option, because there is content in datagrids, that causes postback and needs to remain the menu in the same position as selected value is. So I am doing this as some kind of mapping with a hashtable (e.g. pairs (url-of-the-site, menu-item-to-highlight)), and i have to include a mapping for every site my web application contains in order i want to have menus highlighted... so somehow it bothers me that there has to be a better way to do this. are there any better techniques?

+2  A: 

A technique I use on my master page/content pages with .NET 2.0 is to have a publicly accessible method called "SetNavigation" that takes a string character that correlates to the hyperlink control I want to highlight. What the method does is set the CSS stylesheet of the specified hyperlink to my "selected" one.

Then in my child pages, in the Page_Load method, I call the SetNavigation method and pass in the link based on the current page I'm on, such as SetNavigation("hypSearch")

I would gather that you could create a similar control on your ASCX control and then have your Page_Load events, or even button click events call the method if so desired.

Dillie-O