I have got a master page with three content holders. Say; Header, Menu and Content.
我有一个包含三个内容持有者的母版页。说;标题,菜单和内容。
I can use Iframes or regular frames, but is there a way to specify the three content holders as follows and redirect them to three different web forms? The reason I ask this, is because I do not want to specify my menu over and over again for every single web form.
我可以使用iframe或常规框架,但是有没有办法按如下方式指定三个内容持有者并将它们重定向到三个不同的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>
1 个解决方案
#1
You've missed the point of a master page. A master page should contain the markup/code that is common to the content pages or nested master pages that reference it. Put the menu code into the master page.
你错过了母版页的重点。母版页应包含内容页或引用它的嵌套母版共有的标记/代码。将菜单代码放入母版页。
<!-- 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 >
As an alternative to (or in conjunction with) master pages, you can use 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 principle.
作为母版页的替代(或与之结合使用),您可以使用用户控件。将菜单代码放在用户控件中,并将其嵌入母版页或内容页中。但是如果你总是想要它在同一个地方,那么由于不要重复自己的原则,母版页更有意义。
There is absolutely no reason to use an iframe for this.
绝对没有理由为此使用iframe。
#1
You've missed the point of a master page. A master page should contain the markup/code that is common to the content pages or nested master pages that reference it. Put the menu code into the master page.
你错过了母版页的重点。母版页应包含内容页或引用它的嵌套母版共有的标记/代码。将菜单代码放入母版页。
<!-- 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 >
As an alternative to (or in conjunction with) master pages, you can use 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 principle.
作为母版页的替代(或与之结合使用),您可以使用用户控件。将菜单代码放在用户控件中,并将其嵌入母版页或内容页中。但是如果你总是想要它在同一个地方,那么由于不要重复自己的原则,母版页更有意义。
There is absolutely no reason to use an iframe for this.
绝对没有理由为此使用iframe。