Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   .Selected = false doesn't always work in MenuControl (http://www.velocityreviews.com/forums/t779044-selected-false-doesnt-always-work-in-menucontrol.html)

Wayne Erfling 10-15-2006 10:55 AM

.Selected = false doesn't always work in MenuControl
 
I put in the code below to disable self links in a menu control in a "master" page.

It works properly if the top-level menu item has no children, but both ..Selected = false and .NavigateUrl = null are ignored if the top-level menu item has nested (child) menu items. In other words, the menu item is active and still contains its previous value for ..NavigateUrl.

This looks like a bug to me, and the documentation for .Selected suggests that it should be possible to disable a higher-level item while leaving the lower levels active.

Is there something possibly about doing this in PreRender that is letting the menu control ignore the settings? Or could the child entries somehow be re-invigorating the top-level menu items?

---Wayne

void Page_PreRender(object sender, EventArgs e)
{
// Disable self links (this page == NavigateUrl)

bool bFirstTime = false;
string [] allPaths;
string [] PathParts;
int i;

MenuItemCollection items = idcMasterMenu.Items;

PathParts = Request.Path.Split(new char[] {'/'}) ;

allPaths = (string [])(Session["AllMenuUrls"]);


if (allPaths == null)
{
bFirstTime = true;
allPaths = new string[items.Count];
}


for (i=0; i < items.Count; i++)
{
if (bFirstTime)
allPaths[i] = items[i].NavigateUrl; // be able to restore if nulled out


if (items[i].NavigateUrl.ToLower().IndexOf(PathParts[PathParts.Length-1].ToLower()) > -1)
{
items[i].Selectable = false;
items[i].NavigateUrl = null;
}
else
{
items[i].Selectable = true;
items[i].NavigateUrl = allPaths[i]; // restore from saved values
}
}
if (bFirstTime)
Session["AllMenuUrls"] = allPaths;

} // PreRender





All times are GMT. The time now is 02:51 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.