当前位置:编程学习 > C#/ASP.NET >>

快要疯了

Asp.net中MenuItemClick事件怎么也激发不了,不知道到底是怎么回事,那位大虾帮帮忙 --------------------编程问答-------------------- 后台代码如下:
public partial class site : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
    {       
        
        foreach (MenuItem mi in Menu1.Items)
        {
            if (mi == e.Item)
            {
                mi.ImageUrl = "~/image/iconb_2_1.jpg";
            }
            else 
            { 
                mi.ImageUrl = "~/image/iconb_2_2.jpg";
            }
            
        }
        
    }
}
页面代码如下:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="site.master.cs" Inherits="site" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
    <!--
    body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
    background-image: url(image/bg.gif);
    }
    -->
    </style>    
    <link href="font.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
       <table border="0" cellpadding="0" cellspacing="0" style="width: 778px; height: 100%;" align="center">
            <tr>
                <td style="height: 103px">
                <table border="0" cellpadding="0" cellspacing="0" style="width:100%;height:100%">
                    <tr >
                        <td background="image/top_1.gif" style="height: 60px" colspan="2"></td>
                    </tr>
                    <tr>
                        <td width="750px" style="height: 45px">
                            <asp:Menu ID="Menu1" runat="server"   Orientation="Horizontal" Height="26px" Width="750px" BorderWidth=0 OnMenuItemClick="Menu1_MenuItemClick" 
                            StaticMenuItemStyle-HorizontalPadding="0" StaticMenuItemStyle-ItemSpacing="0" StaticMenuItemStyle-VerticalPadding="0" MaximumDynamicDisplayLevels="0">
                                <Items>
                                    <asp:MenuItem  NavigateUrl="Home.aspx"  ImageUrl="~/image/iconb_2_1.jpg">
                                    </asp:MenuItem>
                                    <asp:MenuItem  NavigateUrl="Home.aspx"  ImageUrl="~/image/iconb_2_2.jpg">
                                    </asp:MenuItem>
                                    <asp:MenuItem  NavigateUrl="Home.aspx"  ImageUrl="~/image/iconb_2_2.jpg">
                                    </asp:MenuItem>
                                    <asp:MenuItem  NavigateUrl="Home.aspx"  ImageUrl="~/image/iconb_2_2.jpg">
                                    </asp:MenuItem>
                                    <asp:MenuItem  NavigateUrl="Home.aspx"  ImageUrl="~/image/iconb_2_2.jpg">
                                    </asp:MenuItem>
                                    <asp:MenuItem  NavigateUrl="Home.aspx"  ImageUrl="~/image/iconb_2_2.jpg">
                                    </asp:MenuItem>
                                    <asp:MenuItem  NavigateUrl="Home.aspx"  ImageUrl="~/image/iconb_2_2.jpg">
                                    </asp:MenuItem>
                                    <asp:MenuItem  NavigateUrl="Home.aspx"  ImageUrl="~/image/iconb_2_2.jpg">
                                    </asp:MenuItem>    
                                    <asp:MenuItem  NavigateUrl="Home.aspx"  ImageUrl="~/image/iconb_2_2.jpg">
                                    </asp:MenuItem>  
                                    <asp:MenuItem  NavigateUrl="Home.aspx"  ImageUrl="~/image/iconb_2_2.jpg">
                                    </asp:MenuItem>                                                                                                                                                                                                                                                        
                                </Items>
                                <StaticMenuItemStyle HorizontalPadding="0px" ItemSpacing="0px" VerticalPadding="0px" />
                            </asp:Menu>
                           
                        </td>
                        <td style="height: 45px"> <asp:LoginStatus ID="LoginStatus1" runat="server" /></td>
                    </tr>
                    <tr>
                        <td colspan="2" style="height: 17px"><img src="image/4.jpg" width="778" height="17" /></td>
                    </tr>
                </table>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
                    </asp:contentplaceholder>
                </td>
            </tr>
            <tr>
                <td align="center">
                版权所有:
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
--------------------编程问答-------------------- 用的是1.帮你顶一下了, --------------------编程问答-------------------- ding --------------------编程问答-------------------- 我也遇到了这个问题,这个原因是这样的,当你使用了NavigateUrl后,MenuItemClick就不能执行,还不知道怎么解决 --------------------编程问答-------------------- MenuItem的RunAt是Server不? --------------------编程问答--------------------
引用 4 楼 zenghongqing 的回复:
我也遇到了这个问题,这个原因是这样的,当你使用了NavigateUrl后,MenuItemClick就不能执行,还不知道怎么解决


正解,好像这控件这么设计 是 避免 冲突 --------------------编程问答-------------------- 这问题好像没遇见过,帮你定啦 --------------------编程问答-------------------- 你先用Response.Write("<script>alert('内容')</script>")这个看能不能弹出东西啊,再调试一下看看啊 --------------------编程问答-------------------- 帮顶! --------------------编程问答-------------------- 学习学习! --------------------编程问答--------------------  我估计是执行了的. 不过又postback了. 建议使用js... --------------------编程问答-------------------- 我是来看你怎么要疯的 --------------------编程问答--------------------
引用 12 楼 taikonhmao67 的回复:
我是来看你怎么要疯的


看热闹也不要这么明显嘛!呵呵 --------------------编程问答-------------------- 我觉得也可以给每个MenuItem加上Click事件试试
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,