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 ...
| |||||||
|
#1
| ||||
| ||||
| 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)
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
| ||||
| ||||
| 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
| ||||
| ||||
| 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
| ||||
| ||||
| 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
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..... |
|
#6
| ||||
| ||||
| 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 />") I just need to fathom out why there's nothing in the menuitemcollection. |
|
#8
| ||||
| ||||
| Quote:
![]() I think it's something to do with the user roles I set for specific menu items. It's getting very frustrating.... |
|
#9
| ||||
| ||||
| 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>
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
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
| ||||
| ||||
| 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. |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |