DeveloperBarn Forums

DeveloperBarn

Programming & IT forum

Accessing skmmenu control in Master Page

This is a discussion on Accessing skmmenu control in Master Page within the .Net Development forums, part of the Programming & Scripting category; I have menu column on the left side of my page that is contained in my Master page. Within that ...

Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

  #1  
Old March 18th, 2008, 08:13 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,347
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default 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 11:37 AM. Reason: Removed [SOLVED] from title
  #2  
Old March 18th, 2008, 08:29 AM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Real name: Jason
Location: Washington, D.C.
Posts: 1,964
Blog Entries: 8
Rep Power: 15
jmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud of
Default

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 with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

If you like it here...throw us a few bones to help
support us.

Join our Folding team: DeveloperBarn Folding

  #3  
Old March 18th, 2008, 09:08 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,347
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default

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  
Old March 18th, 2008, 10:03 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,347
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default

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  
Old March 18th, 2008, 10:06 AM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Real name: Jason
Location: Washington, D.C.
Posts: 1,964
Blog Entries: 8
Rep Power: 15
jmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud of
Default

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.
  #6  
Old March 18th, 2008, 10:12 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,347
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default

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  
Old March 18th, 2008, 10:29 AM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Real name: Jason
Location: Washington, D.C.
Posts: 1,964
Blog Entries: 8
Rep Power: 15
jmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud of
Default

You could always try using the default Menu Control in .Net Indeed, there should be something returned to the MenuItemCollection.
  #8  
Old March 18th, 2008, 10:38 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,347
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default

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  
Old March 18th, 2008, 10:45 AM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Real name: Jason
Location: Washington, D.C.
Posts: 1,964
Blog Entries: 8
Rep Power: 15
jmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud of
Default

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
  #10  
Old March 18th, 2008, 10:57 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,347
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
Default

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

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 02:38 AM.


Copyright ©2008-2010, DeveloperBarn

Content Relevant URLs by vBSEO 3.3.2