Last post Aug 20, 2007 03:55 PM by Russ Helfand
Aug 17, 2007 11:29 AM|janetb|LINK
Going through the walk-throughs and tutorials and have a question about the selected css style. The example shows it posting to the same page and then reflecting the "path" through the menu with a different background color. But, what happens when in real
life it links to a new page? Does the "path" still get reflected after the navigation? As long as it's in a master page? Sorry kids, I'm new to this and a bit slow. Appreciate any explanation.
Aug 17, 2007 04:44 PM|Russ Helfand|LINK
Hi Janet, you might want to study the sample at
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menuitem.selected.aspx. Notice how the menu tag has a convenient attribute, onmenuitemdatabound, that lets you wire up a function that gets executed for each menu item in your menu as it
gets databound. As the example shows, you can use that function to examine whatever properties you wish for the current menu item. Based on those properties (using whatever logic you think is correct for your situation) you can set the Selected property of
one of the menu items.
The adapters will honor the Selected property however it gets set. There is logic within the adapters that facilitates that postback situation because, well, that's necessary in order for the adapters to work. When you are working in a situtation (like you
described) where you are simply building a menu to do plain, old HTTP GET requests on your site, then you have to "manually" set the "selected" page using logic wired up to the onmenuitemdatabound event.
I believe if you wire your menu to a sitemap datasource the menu item gets selected automatically. If you are creating a menu more "manually" with asp:menuitem tags or binding to some other sort of data source you probably can simply add some logic in the
onmenuitemdatabound event and things will work for you.
Aug 20, 2007 11:41 AM|janetb|LINK
Hey Groovey Russ,
Thanks for the reply. I believe I could simply use the sitemap if you think that'd work. I'll have 1-3 menus per page, but they'll have different names, so should work....
Let's just say I wasn't. If the top menu is the same on every page and it's housed in the master also used on every page, would that not get the postback event in the master before the get is processed?
Aug 20, 2007 03:55 PM|Russ Helfand|LINK
If your menu is bound to a sitemapdatasource then when you use it to navigate from page to page there will be no postbacks. This sort of menu uses HTTP GET not HTTP POST to request pages. Still, the master page does get used whenever these pages are loaded.
But everything should just work for you. Give it a shot.