Menu.MenuItem.Click用户控件中的事件 [英] Menu.MenuItem.Click Event within User Control

查看:715
本文介绍了Menu.MenuItem.Click用户控件中的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我创建了一个包含< asp:Menu .. />的用户控件(.ascx)。控制。这个用户控件用于我创建的3个母版页。



我需要在用户选择菜单项时执行一些自定义处理。当然,我连接了一个MenuEventHandler MenuItemClick事件处理程序。我在此代码中设置了一个断点,以查看它是否被击中。奇怪的是,我的断点没有被击中。有人可以告诉我我做错了什么吗?这是我的代码的代码片段:



Control.ascx:



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: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:





Control.ascx.cs:

protected void MenuItem_Click(object sender, MenuEventArgs e)

{

Console.WriteLine("testing");

}



谢谢!


Thank you!

推荐答案

参考 - [MSDN] MenuItem.NavigateUrl 属性 [ ^ ]。

Refer - [MSDN] MenuItem.NavigateUrl Property [^].
引用:

菜单项可以是两个中的一个模式:选择模式或导航模式。默认情况下,菜单项处于选择模式。要将菜单项置于导航模式,请将菜单项的NavigateUrl属性设置为空字符串()以外的值。



当菜单项处于导航模式时,将禁用该菜单项的所有选择事件。在导航模式下单击菜单项会将用户带到指定的URL。您可以选择设置Target属性以指定显示链接内容的窗口或框架。

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.



因此,请检查 MenuItems ,如果您已经定义了 NavigateUrl 属性。

如果已定义,则删除并检查。该事件将被解雇。


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.


我完全同意 Tadit Menu-MenuItem-ClickplusEventpluswithinplusUserplus>解决方案1 ​​ [ ^ ]。



在这里,我添加了一些关于 ASP.NET Web服务器控件事件模型 [ ^ ]。



onClick 事件> MenuItem 仅在没有 NavigateUrl 设置时触发对于item.If你看一下页面的来源,当它呈现给浏览器时,你会注意到 MenuItems 有一个 NavigateUrl set将呈现为simp le span标签内的span锚标签,意味着不会发生回发并且事件处理程序不会触发。







- 艾米
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


这篇关于Menu.MenuItem.Click用户控件中的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆