In Menu Control's item collection, setting .Selected=false doesn't work if children present

W

Wayne Erfling

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.

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 = items.NavigateUrl; // be able to restore if nulled out


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

} // PreRender
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top