Contentholder 作为 asp.net 中 Web 表单的引用
Contentholder as reference to web form in asp.net
我有一个包含三个内容持有者的母版页。说;页眉、菜单和内容。
我可以使用 Iframe 或常规框架,但有没有办法指定如下三个内容持有者并将它们重定向到三个不同的 Web 表单?
我问这个的原因是因为我不想为每个 Web 表单一遍又一遍地指定我的菜单。
<asp:Content ID="Content1" ContentPlaceHolderID="Header" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Menu" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Content" runat="server">
</asp:Content>
您错过了母版页的要点。母版页应包含内容页或引用它的嵌套母版页共有的 markup/code。将菜单代码放入母版页。
<!-- Menu code here -->
<ul class="menu">
<li><a href="Home">Home"</a></li>
<li><a href="Contact">Contact"</a></li>
</ul>
!-- End menu code -->
<asp:ContentPlaceHolder ID="MenuPlaceHolder" runat="server">
<!-- On the content page, your page specific menu code would go in the <asp:Content> that references this -->
</asp:ContentPlaceHolder >
作为母版页的替代(或结合),您可以使用 user controls. You place your menu code in the user control and embed it in master pages or content pages. But if you always want it in the same place, then a master page makes more sense because of the Don't Repeat Yourself 原则。
绝对没有理由为此使用 iframe。
我有一个包含三个内容持有者的母版页。说;页眉、菜单和内容。
我可以使用 Iframe 或常规框架,但有没有办法指定如下三个内容持有者并将它们重定向到三个不同的 Web 表单? 我问这个的原因是因为我不想为每个 Web 表单一遍又一遍地指定我的菜单。
<asp:Content ID="Content1" ContentPlaceHolderID="Header" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Menu" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Content" runat="server">
</asp:Content>
您错过了母版页的要点。母版页应包含内容页或引用它的嵌套母版页共有的 markup/code。将菜单代码放入母版页。
<!-- Menu code here -->
<ul class="menu">
<li><a href="Home">Home"</a></li>
<li><a href="Contact">Contact"</a></li>
</ul>
!-- End menu code -->
<asp:ContentPlaceHolder ID="MenuPlaceHolder" runat="server">
<!-- On the content page, your page specific menu code would go in the <asp:Content> that references this -->
</asp:ContentPlaceHolder >
作为母版页的替代(或结合),您可以使用 user controls. You place your menu code in the user control and embed it in master pages or content pages. But if you always want it in the same place, then a master page makes more sense because of the Don't Repeat Yourself 原则。
绝对没有理由为此使用 iframe。