Closed Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14

Thread: Accessing skmmenu control in Master Page

  1. #1
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Accessing skmmenu control in Master Page

    I have menu column on the left side of my page that is contained in my Master page. Within that menu is a list showing how many tasks a user has that are overdue, due in a week and due in more than a week.

    It has a seperate label to show if they have a new task or an updated task.

    When the user goes into an updated task (let's assume they only have 1) I want to update the label in the left menu as the page loads.

    I have a routine that builds the specific task list element, so I basically want to update the menu in the Page_Load event of my task view page.

    The code I use to access the menu control is:-
    Code:
    Dim left_menu as skmMenu.Menu = Master.FindControl("left_menu")
    Dim tasklist as skmMenu.Menuitem = left_menu.FindControl("tasklist") ' this is the id of the menu item for the tasklist
    left_menu.items.remove(tasklist)
    ledt_menu.items.add(Master.left_menu_tasklist)
    
    As soon as I do anything with the control, it just gets rid of the whole menu.

    What I want to happen is when they load the updated task (assuming they only have 1), the left menu shows that they now have no updated tasks.

    Any ideas I how I can just update the tasklist element?
    Last edited by richyrich; May 6th, 2008 at 12:37 PM. Reason: Removed [SOLVED] from title

  2. #2
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,533
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    I've never used the skmMenu, myself. I'm not sure I understand where the label comes into play with this either. Is the label simply a label control? A part of the skmMenu?

    Any matter, perhaps you need to approach this differently. Instead of trying to find the menuitem by ID, have you tried accessing it by the Items collection?

    Sorry I couldn't be of more help. Like I said, I don't use this control.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  3. #3
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Sorry, I may have confused with using label to describe the section I want to change. It's not a label control.

    Basically, I have a routine that gets all the task data and then adds it to my skmMenu as a menu item.

    Each skmMenu item has text, tooltip, id and URL properties, amongst others.

    What I want to do is call this routine to update the tasklist menu item text element.

    I can't seem to get it to find the specific menu item though.

    Will keep playing around with it...

  4. #4
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    I just don't get this...
    In my code behind
    Code:
    Dim left_menu as skmMenu.Menu = Master.FindControl("left_menu")
    Dim menu_items as akmMenu.MenuItemCollection = left_menu.items
    response.write(menu_items.tostring & "<br />") ' <- returns skmMenu.MenuItemCollection
    response.write(menu_items.Count & "<br />") '<-returns 0
    
    Why is there nothing in the MenuItemCollection? Is not actually finding the left_menu control on the Master page? If not, why doesn't this generate an error?

    If I try a for each menu_item in menu_items, nothing gets returned. Actually, I guess the first response.write is bound to return that as I just set it to a menuitemcollection. I presume it's not getting the control from the Master page then.

    I'm confused.....

    Please help.....

  5. #5
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,533
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Do you get a different result if the menu wasn't being accessed through a MasterPage? Try something simple first and see if that works.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  6. #6
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Will try that if I don't get any further with this J.

    Right, now if I try this, it returns the correct cssClass
    Code:
    response.write(left_menu.SelectedMenuItemStyle.CssClass.ToString & "<br />")
    
    So, it must be finding the left_menu control in the master page inorder to return the cssClass property.

    I just need to fathom out why there's nothing in the menuitemcollection.

  7. #7
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,533
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    You could always try using the default Menu Control in .Net Indeed, there should be something returned to the MenuItemCollection.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  8. #8
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by jmurrayhead View Post
    You could always try using the default Menu Control in .Net Indeed, there should be something returned to the MenuItemCollection.
    I use the skmMenu for a specific reason, that I can't quite remember now...

    I think it's something to do with the user roles I set for specific menu items.

    It's getting very frustrating....

  9. #9
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,533
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Check out this function I wrote:

    I got this idea from helping another member with some similar code. This uses the Menu Class to build a menu a populates it from a database, allowing for multiple child menus. Sample files are included.
    Menu.aspx
    Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="menu.aspx.vb" Inherits="_Menu"%>
    <html>
    <head>
        <title>Recursive Menu Example</title>
    </head>
        <body>
            <form id="Form1" runat="server">
                <asp:Panel ID="Panel1" runat="server" />
            </form>
        </body>
    </html>
    
    menu.aspx.vb
    Code:
    Imports System.Data.OleDb
    Partial Class _Menu
        Inherits System.Web.UI.Page
        '//Connection to database from web.config file
        Private conn As New OleDbConnection(ConfigurationManager.ConnectionStrings("menu").ConnectionString)
        Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            Call PopulateMenu()
        End Sub
        Private Sub PopulateMenu()
            Try
                '//Define new menu
                Dim menu As New Menu()
                '//Retrieve menu data
                Dim menuData As DataTable = GetMenuData()
                AddTopMenuItems(menuData, menu)
                Me.Panel1.Controls.Add(menu)
                Me.Panel1.DataBind()
            Catch ex As Exception
                Response.Write(ex.Message.ToString() & "<br />")
            End Try
        End Sub
        Private Function GetMenuData() As DataTable
            Try
                '//Populate DataTable
                Dim strSQL As String = "SELECT * FROM tbl_menu"
                Dim datMenu As OleDbDataAdapter = New OleDbDataAdapter(strSQL, conn)
                Dim tblMenu As DataTable = New DataTable()
                datMenu.Fill(tblMenu)
                Return tblMenu
            Catch ex As Exception
                Response.Write(ex.Message.ToString() & "<br />")
            End Try        
        End Function
        Private Sub AddTopMenuItems(ByVal menuData As DataTable, ByVal menu As Menu)
            Try
                '//Populate DataView
                Dim datView As DataView = New DataView(menuData)
                '//Filter parent menu items
                datView.RowFilter = "parentid = 0"
                '//Populate menu with top menu items
                Dim datRow As DataRowView
                For Each datRow In datView
                    '//Define new menu item
                    Dim parentMenu As MenuItem
                    parentMenu = CreateMenuItem(datRow("linktext"), datRow("linkurl"), datRow("linktext"))
                    menu.Items.Add(parentMenu)
                    '//Populate child items of this parent
                    AddChildMenuItems(menuData, datRow("itemid"), parentMenu)
                Next
            Catch ex As Exception
                Response.Write(ex.Message.ToString() & "<br />")
            End Try
        End Sub
        Private Sub AddChildMenuItems(ByVal menuData As DataTable, ByVal parentID As Integer, Byval parentMenu As MenuItem)
            Try
                '//Populate DataView
                Dim datView As DataView = New DataView(menuData)
            
                '//Filter child menu items
                datView.RowFilter = "parentid = " & parentID
                '//Populate parent menu item with child menu items
                Dim datRow As DataRowView
                For Each datRow in datView
                    '//Define new menu item
                    Dim childMenu As MenuItem
                    childMenu = CreateMenuItem(datRow("linktext"), datRow("linkurl"), datRow("linktext"))
                    parentMenu.ChildItems.Add(childMenu)
                    '//Populate child items of this parent
                    AddChildMenuItems(menuData, datRow("itemid"), childMenu)
                Next
            Catch ex As Exception
                Response.Write(ex.Message.ToString() & "<br />")
            End Try
        End Sub
        Private Function CreateMenuItem(ByVal strText As String, ByVal strUrl As String, ByVal strToolTip As String) As MenuItem
            Try
                '//Create new menu item
                Dim menuItem As New menuItem()
                '//Set properties of the menu item
                With menuItem
                    .Text = strText
                    .NavigateUrl = strUrl
                    .ToolTip = strToolTip
                End With
                Return menuItem
            Catch ex As Exception
                Response.Write(ex.Message.ToString() & "<br />")
            End Try        
        End Function
    End Class
    
    Table design:
    This setup uses a table with the following field types:
    itemid - AutoNumber
    parentid - Number
    linktext - Text
    linkurl - Text
    Parent items will have parentid = 0 whereas child items will have parentid = itemid of the parent.

    As you should be able to see...you can easily implement user role checking in this code (as I have done so before) just by adding a column in the table and checking it against the current user's role before adding the item to the list
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  10. #10
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Thanks for the code J. Trouble is I have several dynamic elements that return different items to the menu depending on various queries. It's not a static menu.

    I think I've kind of worked it out now. If I add a response.write(left_menu.items.count) to the Master Page it shows the correct number of items.

    If I go into the view task page, the master page count is rendering after the view task page count. Presumably the menu items are being rendered to the browser after I try and access the menu item collection in the view task page, so it's returning 0.

    So if I create a public value in the master page containing what I need, I should be able to access that on the included page.

    Bit long winded, but should do it. Just need to fiddle around to get the detail I need.

Closed Thread
Page 1 of 2 1 2 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO