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: 2/14/2006 5:08:46 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 1 Views: 64 Favorited: 0 Favorite
2 Items, 1 Pages 1 |< << Go >> >|
Keep it Simple
Asp.Net User
OnMenuItemDataBound2/14/2006 5:08:46 AM

0

Hi, I'm using VWD 2005 Express and have downloaded a corporate template web site from Microsoft:

http://msdn.microsoft.com/asp.net/reference/design/templates/default.aspx

In the AppMaster master page it has a Menu control called 'mainmenu' with the following:

<asp:Menu DataSourceID="sitemap" ID="mainmenu" SkinID="mainmenu" runat="server" OnMenuItemDataBound="MainMenu_MenuItemDataBound" />

I believe, the prewritten function MainMenu_MenuItemDataBound in the codebehind file checks to see if a node is an ancestor. Here is the prewrtiten code:

Protected Sub MainMenu_MenuItemDataBound(ByVal sender As Object, ByVal e As MenuEventArgs)
   If mainmenu.SelectedItem Is Nothing Then
      
If IsNodeAncestor(CType(e.Item.DataItem, SiteMapNode), System.Web.SiteMap.CurrentNode) Then
         
e.Item.Selected = True
      
End If
   
End If
End Sub

Private Function IsNodeAncestor(ByVal ancestor As SiteMapNode, ByVal child As SiteMapNode) As Boolean

   Dim result As Boolean = False
   
If Not ancestor.ChildNodes Is Nothing AndAlso ancestor.ChildNodes.Contains(child) Then
      
Return True
   
Else
      
If (Not child.ParentNode Is Nothing) AndAlso (Not ancestor Is child.RootNode) Then
         
Return IsNodeAncestor(ancestor, child.ParentNode)
      
End If
   
End If
   
Return result
End Function

If I create a new aspx page e.g. news.aspx and run it, I get errors regarding referencing a NULL value or something along those lines. What I discovered was that I had to put the "news.aspx" page in my Web.sitemap file for it to work. But it was then listed in the main menu, whn it should just be another low profile page someweher in the web site.

I don't want everybody to be able to see all pages (news.aspx is an exception) and have them listed in the main menu etc or have them listed in the Web.sitemap file. I've found some technotes referring to security roles etc but it seemed over the top for creating a news page (for example)

QUESTIONS:

1. Why does the program need to know if a node in the main menu is an ancestor?

2. What does the parameter OnMenuItemDataBound actually do? I assume it is an instruction to go and execute a procedure or function

3. Do I have to have it with menu controls?

I have deleted the OnMenuItemDataBound parameter and commented out the above function code in the AppMaster code behind and it seems to work. This I guess answers the third question, but I would like confirmation, please.

Thank you


John
dannychen
Asp.Net User
Re: OnMenuItemDataBound2/16/2006 1:56:51 AM

0

The reason that code is in place is to let the Menu show a node as "selected" if it is the parent of the current page being visited.  If you disable the code, your Menu should work just fine except that if your at a page which is the child of a Menu item, it won't show that item as selected.

The reason your news.aspx page showed up in your menu is because you probably added it as a top level item.  My guess is that the SiteMapDataSource/Menu are configured to only show 1 or 2 levels of hierarchy.  If you put news.aspx at a lower level in your web.sitemap, such as under one of the top level nodes, then it probably won't appear in your top level Menu.  Otherwise, it's a simple matter of choosing the combination of 3 properties to fit yourneeds:

Menu:
  StaticDisplayLevels
  MaximumDynamicDisplayLevels (probably 0)

SiteMapDataSource:
  ShowStartingNode

--
Danny


disclaimer: Information provided is 'as is' and conveys no warranties or guarantees.
2 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
ASP.net 2.0 Illustrated: [deutsche Ausgabe] Authors: Alex Homer Dave Sussman, Alex Homer, Dave Sussman, Pages: 668, Published: 2007

Web:
Menu.OnMenuItemDataBound Method (System.Web.UI.WebControls) Protected Overridable Sub OnMenuItemDataBound ( _ e As MenuEventArgs _ ) ... protected virtual void OnMenuItemDataBound( MenuEventArgs e ) ...
Menu.MenuItemDataBound Event (System.Web.UI.WebControls) System.Web.UI.WebControls Namespace · MenuEventArgs · MenuEventHandler · Menu. MenuItemClick Event · OnMenuItemDataBound ...
OnMenuItemDataBound - ASP.NET Forums What does the parameter OnMenuItemDataBound actually do? I assume it is an instruction to go and execute a procedure or function ...
Simple menu control shows childitems count =0 : childitems ... I do this in *** OnMenuItemDataBound *** ****... ... Tags: childitems, control, menu, onmenuitemdatabound. This cant be that hard. ...
How to hide some map nodes from menu Use the OnMenuItemDataBound event and you can check which node you're on by looking at the menu item's text. ...
newbie: Problems creating asp.net 2.0 Menu StaticMenuItemStyle-CssClass="menuitem" StaticHoverStyle-CssClass="menuitem: hover" OnMenuItemDataBound="mnuSidebar_MenuItemDataBound" > ...
OnMenuItemClick and OnMenuItemDatabound - ASP.NET Forums NET » Master Pages, Themes and Navigation Controls » OnMenuItemClick and OnMenuItemDatabound ... Re: OnMenuItemClick and OnMenuItemDatabound ...
DotNetSlackers: Customizing Individual Menu Items Dec 2, 2005 ... OnMenuItemDataBound="Menu1_MenuItemDataBound"> Adding MouseOver Images to the ASP.NET 2.0 Menu Control - Jeff Cleath Intellisence wasn't picking up the "onmenuitemdatabound" in the control. ... < asp:Menu onmenuitemdatabound="_siteMenu_ItemDataBound" ID="Menu1" ...
Mack the # Implement: Tweaking the SiteMap Navigation Menu Feb 29, 2008 ... Then I mapped the OnMenuItemDataBound event to a custom handler.






impersonation and user not logged on into the server

execute code after login/authenticating via forms authentication

not log on

recording user logout when close the browser.

please help, i am really confussed

login control not working

get current username

create new user with a profile and role but already logged in as admin. please advise....thank you.

encryption, php and asp.net

trouble when try yo administer my web site in asp.net 2.0

findcontrol in createuserwizard problems

how to do wildcard mapping in iis 5.1?

setauthcookie and userdata

protecting pdf files

adding role to user by registration bug?

membership stored procedures not ansi sql compliant

web form log in with active directory

permission

com+ and web services

basic autentication

custom membership provider + session values is it workable??

determining username/role

custom membership provider and changepassword issue

users online

authenticating accounts/contacts from crm

problem with new users

asp.net security across servers

membershipstatus

why not running(update) login,create user, with iis?

access database membership provider

   
  Privacy | Contact Us
All Times Are GMT