473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Dynamic menu items not raising Click event?

Here's the 30,000-ft. view: I wrapped an asp:Menu control in an ascx control. When I try to dynamically populate the menu in the ascx control, the items appear, but clicking on them fails to trigger the MenuItemClick event handler. However, if I statically declare the menu items in the .ascx page, everything is fine. Any ideas?

Here's the details:

My ascx page:

Expand|Select|Wrap|Line Numbers
  1. <%@ Control Language="VB" AutoEventWireup="false" CodeFile="TabStrip.ascx.vb" Inherits="TabStrip" %>
  2. <asp:Menu runat='server' ID='muStrip' orientation='horizontal'>
  3. </asp:Menu>
  4.  
Code in my ascx.vb file:

Expand|Select|Wrap|Line Numbers
  1. ...
  2.     Public Sub AddItem(ByVal sText As String, ByVal bSelected As Boolean)
  3.         If (bSelected) Then
  4.             For i As Integer = 0 To muStrip.Items.Count - 1
  5.                 muStrip.Items(i).Selected = False
  6.             Next
  7.         End If
  8.         Dim mui As New MenuItem(sText)
  9.         mui.Selectable = True
  10.         mui.Selected = bSelected
  11.         muStrip.Items.Add(mui)
  12.     End Sub
  13.  
  14.     Protected Sub muStrip_MenuItemClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles muStrip.MenuItemClick
  15.         ' Raise user event handler.
  16.         RaiseEvent ItemClick(sender, e, miSelectedItem)
  17.     End Sub
  18. ...
  19.  
Code in my calling-page .vb file:

Expand|Select|Wrap|Line Numbers
  1. ...
  2.     Protected Overrides Sub HandlePageLoad()
  3.         MyBase.HandlePageLoad()
  4.  
  5.         ' Populate the tab strip.
  6.         If Not Page.IsPostBack Then
  7.             oxiTab.AddItem("  Administrative", True)
  8.             oxiTab.AddItem("  Maintenance", False)
  9.             oxiTab.AddItem("  Tests/Requests", False)
  10.             oxiTab.AddItem("  Reports", False)
  11.         End If
  12.     End Sub
  13. ...
  14.  
If I put a breakpoint at the "RaiseEvent" call and try clicking on any menu item, I never reach the breakpoint. But if I add static menu items in the ascx page, the breakpoint IS reached.

Thanks.
Jan 5 '07 #1
1 7131
Click Event for dynamically added toolstripmenu items



SqlCommand cmd = new SqlCommand("select mytablename from ds_table", con);
SqlDataAdapter da= new SqlDataAdapter(cmd);
con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
SqlDataReader dr = cmd.ExecuteReader();

MenuStrip menu = new MenuStrip();
ToolStripMenuItem item = new ToolStripMenuItem("Reports");
while (dr.Read())
{
ToolStripMenuItem inneritem = new ToolStripMenuItem(dr["mytablename"].ToString());

item.DropDownItems.Add(inneritem);
menu.Items.Add(item);
this.Controls.Add(menu);
inneritem.Click += new EventHandler(inneritem_Click);

}
con.Close();
Jan 28 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
10
by: tmaster | last post by:
When I try to dynamically add a second sub menu item to this ContextMenu item, I get an error 'Specified argument was out of the range of valid values'. Private Sub mnuTopics_Show_Select(ByVal...
1
by: Chris Murphy via DotNetMonster.com | last post by:
Hi all, I'm just wondering if any one can help me with this development issue I'm having. I've created a customized treeview control to handle the particular tasks to which I'll be using it. Within...
2
by: Ron M. Newman | last post by:
Hi, Just need a little advice. Id like to build *dynamic* context menus for tree nodes. I'm pretty versed in building context menus and attaching them to tree nodes. My question is, what...
3
by: =?Utf-8?B?ZWFndWlsYXI=?= | last post by:
Hi, I am trying to dynamically generate a menu, based on entries on a text or xml file. The text file contains the "tree" after which the menu will need to be created. Something like the...
1
by: Karl Rhodes | last post by:
I'm building a windows forms app in VB.net 2005 and would like to know if there is any way of adding a handler using a dynamic AddressOf value? The application will have a "Windows" menu item...
13
by: PetterL | last post by:
I writing a program where I read menu items from a file. But I have problem when I click an menu item i want it to mark that one as checked but I cant access the menu object of that item to see...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
4
by: libish | last post by:
hi all... can any one help me by suggesting a way to get items in dynamic form? here what i'm doing is , i'm displaying a dynamic form. in that form i have a main menu and this main menu contains...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.