简体   繁体   English

在asp.net菜单中未触发MenuItem事件

[英]MenuItem event wasn't triggered in asp.net menu

The menu item click event was failed to trigger code behind event method when click the menu item. 单击菜单项时,菜单项单击事件无法触发事件方法后面的代码。 I added the OnMenuItemClick(Menu_Item_Click) at menu even though it was getting failed to trigger the code behind event. 我在菜单中添加了OnMenuItemClick(Menu_Item_Click),即使它未能触发事件后面的代码。

How can i sort it out this issue? 我该如何解决这个问题呢?

/** Asp.net Template code goes here **/ / ** Asp.net模板代码在这里** /

     <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" 
            EnableViewState="True" IncludeStyleBlock="False" Orientation="Horizontal" 
            BackColor="#F7F6F3" DynamicHorizontalOffset="2" Font-Names="Arial, Helvetica, sans-serif"
            Font-Size="0.8em" ForeColor="#7C6F57" StaticSubMenuIndent="10px" OnMenuItemClick="Menu_Item_Click">

<Items>
<asp:MenuItem NavigateUrl="~/Default.aspx"  Text="Default">
<asp:MenuItem NavigateUrl="~/Search.aspx" Text="Search">
</Items>
</asp:Menu>

Codebehind Code Goes here Codebehind Code就在这里

protected void Menu_Item_Click ( object sender, MenuEventArgs e )
{
   /** Some Validation goes here **/
}

I also experienced this problem. 我也遇到过这个问题。 I solved it by eliminating the field NavigateUrl. 我通过消除NavigateUrl字段解决了这个问题。 If you eliminate this field then the click event will be triggered. 如果删除此字段,则会触发click事件。 In the function(event handler function) you can use the following code to navigate to the necessary page using the following code. 在函数(事件处理函数)中,您可以使用以下代码使用以下代码导航到必要的页面。

protected void MainMenu_MenuItemClick(object sender, MenuEventArgs e)
{
    /*your necessary code*/
    Response.Redirect(((Menu)sender).SelectedItem.Target);

}

In the above code TargetField is specified in the Menu tag with the necessary address. 在上面的代码中, TargetField在Menu标签中指定了必要的地址。

or you can specify the address directly by. 或者您可以直接指定地址。

protected void MainMenu_MenuItemClick(object sender, MenuEventArgs e)
{
    /*your necessary code*/
    Response.Redirect("Page.aspx");

}

According to your code and description ,for my experience the issue is related to the text and the value properties of menuitem are not specified. 根据您的代码和描述,根据我的经验,该问题与文本有关,并且未指定menuitem的value属性。

Ex: 例如:

 <asp:Menu runat="server" ID="MainMenuCtl" BorderWidth="0"
            Orientation="Vertical" onmenuitemclick="MainMenuCtl_MenuItemClick">
            <Items>
                <asp:MenuItem ImageUrl="~\App_Themes/SiteDefault/Images/Mediabutton.png" value="&nbsp;" ToolTip="Media Clips">
                </asp:MenuItem>
                <asp:MenuItem ImageUrl="~\App_Themes/SiteDefault/Images/CalendarButton.png" value="&nbsp;&nbsp;" ToolTip="View calendar of events">
                </asp:MenuItem>
                <asp:MenuItem ImageUrl="~\App_Themes/SiteDefault/Images/PoetryButtonReg.png" value="&nbsp;&nbsp;&nbsp;" ToolTip="Poetry">
                </asp:MenuItem>
            </Items>
        </asp:Menu>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM