如何将母版页添加到现有页 [英] how to add master page to existing page
问题描述
嗨...
我已经创建了一个网页...
但是我没有包含母版页...
现在我想在其中包含母版页吗?
我该怎么做?
hi...
i am created a webpage already...
but i didn''t include master page in it...
now i want to include master page in it?
how can i do this ?
推荐答案
首先将MasterPageFile属性添加到Page指令:
First you add the MasterPageFile attribute to the Page directive:
<%@ Page MasterPageFile="myMaster.master" %>
您需要删除除form标记内容之外的所有内容-包括删除form标记本身,因为这将在母版页中.然后使用Content控件包装这些表单内容:
The you need to remove everything apart from the contents of the form tag - that includes removing the form tag itself, as this will be in the master page. Then wrap those form contents with a Content control:
<asp:Content id="myContent" runat="server" ContentPlaceholderId="MasterID">
page contents
</asp:Content>
ContentPlaceHolderID的值应该是母版页中ContentPlaceHolder控件的ID.
The value of ContentPlaceHolderID should be the ID of the ContentPlaceHolder control from the master page.
在页面指令中添加此属性
In page directive add this property
MasterPageFile="~/MasterPages/AdminMaster.master"
如下图所示
as shown below
<%@ Page Language="C#" MasterPageFile="~/MasterPages/AdminMaster.master" AutoEventWireup="true"
CodeFile="AdminInvestments.aspx.cs" Inherits="AdminInvestments" %>
然后删除html,head和body标签
并按如下所示放置<asp:content>
标签
Then remove html,head and body tags
and place <asp:content>
tag as below
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
//Here paste body content
这里ContentPlaceHolder2
是母版页中的contentplaceholderid
here ContentPlaceHolder2
is contentplaceholderid in master page
查看此链接
http://forums.asp.net/p/881332/910714.aspx [ ^ ]
See this link
http://forums.asp.net/p/881332/910714.aspx[^]
这篇关于如何将母版页添加到现有页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!