Click here to Skip to main content
15,173,031 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello,

I have created a user control (.ascx) that contains an <asp:Menu .. /> control. This user control is used across 3 master pages that I have created.

I need to perform some custom handling when a user selects a menu item. Naturally, I wired-up a MenuEventHandler MenuItemClick event handler. I have set a break point in this code to see if it is being hit. Strangely, my breakpoint is not being hit. Can someone please tell me what I am doing incorrectly? Here is a code snippet of my code:

Control.ascx:

ASP.NET
<asp:Menu ID="TestMenu" runat="server" Orientation="Horizontal" MaximumDynamicDisplayLevels="2" StaticEnableDefaultPopOutImage="False" DataSourceID="SiteMap1" EnableTheming="False" StaticPopOutImageUrl="~/App_Themes/Images/menu/popout.gif" OnMenuItemClick="MenuItem_Click" />


Control.ascx.cs:

C#
protected void MenuItem_Click(object sender, MenuEventArgs e)

{

Console.WriteLine("testing");

}

Thank you!
Posted
Updated 28-May-13 8:31am
v2

Refer - [MSDN] MenuItem.NavigateUrl Property [^].
Quote:
A menu item can be in one of two modes: selection mode or navigation mode. By default, a menu item is in selection mode. To put a menu item into navigation mode, set the menu item's NavigateUrl property to a value other than an empty string ("").

When a menu item is in navigation mode, all selection events are disabled for that menu item. Clicking the menu item in navigation mode takes the user to the specified URL. You can optionally set the Target property to specify the window or frame in which to display the linked content.

So, check your MenuItems, if you have defined the NavigateUrl property or not.
If you have defined, then delete that and check. The event will get fired.
   
v2
Comments
_Amy 28-May-13 23:53pm
   
+5!
   
Thanks a lot @_Amy...
I am totally agree with Tadit in Solution 1[^].

Here, I am adding some more information about ASP.NET Web Server Control Event Model[^].

The onClick event for a MenuItem only fires when there is not a NavigateUrl set for the item.If you take a look at the source of the page as it is rendered to the browser, you will notice that MenuItems that have a NavigateUrl set will render as simple anchor tags inside of a span, which means no postback will occur and the event handler will not fire.



--Amy
   
Comments
Rockstar_ 29-May-13 0:02am
   
Well Explained...
_Amy 29-May-13 0:03am
   
Thanks. :)
_Amy 29-May-13 2:35am
   
Thank you Tadit. :)
   
That is Tadit... :P :D
_Amy 29-May-13 2:37am
   
Oh Sorry. :( Edited Now. :)
   
No problem... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900