473,714 Members | 2,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic menu items not raising Click event?

8 New Member
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 7160
rajeshthangarasu1983
3 New Member
Click Event for dynamically added toolstripmenu items



SqlCommand cmd = new SqlCommand("sel ect mytablename from ds_table", con);
SqlDataAdapter da= new SqlDataAdapter( cmd);
con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
SqlDataReader dr = cmd.ExecuteRead er();

MenuStrip menu = new MenuStrip();
ToolStripMenuIt em item = new ToolStripMenuIt em("Reports");
while (dr.Read())
{
ToolStripMenuIt em inneritem = new ToolStripMenuIt em(dr["mytablenam e"].ToString());

item.DropDownIt ems.Add(innerit em);
menu.Items.Add( item);
this.Controls.A dd(menu);
inneritem.Click += new EventHandler(in neritem_Click);

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

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

Similar topics

1
17666
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 Create a Dynamic Crosstab Report PRODUCT :Microsoft Access PROD/VER:1.00 1.10 OPER/SYS:WINDOWS
10
21317
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 sender As System.Object, _ ByVal e As System.EventArgs) _ Handles mnuTopics_Show.Select Dim mShowMenuItem As MenuItem mShowMenuItem = DirectCast(sender, MenuItem)
1
2720
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 the control I'm dynamically creating a context menu and assigning it to the ContextMenu property of the control -- think of this like the default context menu for standard textboxes -- the context menu has a number of menu items that reflect...
2
3450
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 event to I "capture" in order to build the tree node menu in real time? right click on a tree node? or is it too late? just FYI: the menu is different for each node and is based on "real time"
3
3013
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 following: Level 1 -- Level 2 -- Level 2 Level 1
1
3424
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 and I want to add a list open forms as other menu items to this list. I want to be able to do this dynamically and create a handler for each one that I add. However, instead of creating the handler everytime i open a new form, I want to use a...
13
2853
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 witch object was selected. This is the sub procedure that read the items from an Array and create the menutitem. The array hold more information to use in program when one of the items is selected. Dim finisharray(,) As String ' is set up...
0
2724
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, cannot serch by combine 3 table) Example I have the query table below, how do I make the code to seach based on the query from this: SELECT Product.ID, Product.Description, Quantity.Quantity, Quantity.SeialNo, Quantity.SupplierID,...
4
1846
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 a menu item "OK". here the dynamic form consist of some labels, list items and all. when i click on the "OK" menu item, an event occurs and i've wrote methods which wll execute on this event. now i need the selected list item index,value.. label...
0
8801
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8707
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9015
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6634
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5947
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4725
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2520
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2110
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.