无法显示asp:menu,控件未在运行时显示

时间:2013-01-14 19:56:06

标签: asp.net controls visible master aspmenu

我有一个奇怪的问题。我在我的.master页面添加了一个asp:menu控件。还添加了一些项目和子项目。但是,我不知道为什么,我可以在设计时看到控件,但我在运行时找不到它。 visible属性设置为true。即使查看源代码,控件也会丢失。

这是代码

 <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="CMSFirst.master.cs" Inherits="CMSFirst.CMSFirst" %>

 <!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></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
   </asp:ContentPlaceHolder>
</head>
  <body>
    <form id="form1" runat="server">

 <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
                <asp:Menu ID="Menu2" runat="server">
                    <Items>
                        <asp:MenuItem Text="Članki" Value="Nov"></asp:MenuItem>
                        <asp:MenuItem Text="Nastavitve" Value="Nastavitve">
                            <asp:MenuItem Text="Pisava" Value="Pisava"></asp:MenuItem>
                            <asp:MenuItem Text="Oblika" Value="Oblika"></asp:MenuItem>
                        </asp:MenuItem>
                        <asp:MenuItem Text="Pomoč" Value="Pomoč"></asp:MenuItem>
                    </Items>
                </asp:Menu>
            </asp:ContentPlaceHolder>


<table border="0" cellpadding="2" cellspacing="0">
    <tr>
        <td>
            <img src="Images/logo.jpg" alt="CMSFirst" />
        </td>
    </tr>
    <tr>
        <td>
              <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                <asp:Menu ID="Menu1" runat="server">
                    <Items>
                        <asp:MenuItem Text="Članki" Value="Nov"></asp:MenuItem>
                        <asp:MenuItem Text="Nastavitve" Value="Nastavitve">
                            <asp:MenuItem Text="Pisava" Value="Pisava"></asp:MenuItem>
                            <asp:MenuItem Text="Oblika" Value="Oblika"></asp:MenuItem>
                        </asp:MenuItem>
                        <asp:MenuItem Text="Pomoč" Value="Pomoč"></asp:MenuItem>
                    </Items>
                </asp:Menu>
             </asp:ContentPlaceHolder>
        </td>
    </tr>
    <tr>
        <td>
            <p>
                <strong>Website design by Me</strong></p>
            <asp:LoginStatus ID="LoginStatus1" runat="server" />
        </td>
    </tr>
</table>
</form>

我搜索了很多东西,但找不到原因。

由于

1 个答案:

答案 0 :(得分:0)

我的样本母版页面带有一个菜单:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="SiteMaster" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
    <title></title>
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form runat="server">
    <div class="page">
        <div class="header">
            <div class="title">
                <h1>
                    My ASP.NET Application
                </h1>
            </div>
            <div class="clear hideSkiplink">
                <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false"
                    IncludeStyleBlock="false" Orientation="Horizontal">
                    <Items>
                        <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home" />
                        <asp:MenuItem NavigateUrl="~/About.aspx" Text="About" />
                    </Items>
                </asp:Menu>
            </div>
        </div>
        <div class="main">
            <asp:ContentPlaceHolder ID="MainContent" runat="server" />
        </div>
        <div class="clear">
        </div>
    </div>
    <div class="footer">
    </div>
    </form>
</body>
</html>

我的默认页面

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Welcome to ASP.NET!
    </h2>
    <p>
        To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
    </p>
    <p>
        You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409"
            title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
    </p>
</asp:Content>

我的样本关于页面

<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="About.aspx.cs" Inherits="About" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        About
    </h2>
    <p>
        Put content here.
    </p>
</asp:Content>