在内容页面,想对母版页的控件引用调用或者修改怎么办?
1.母版页如下
<%@ Master Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
</style>
<title>Master</title>
</head>
<body>
<form id="form1" runat="server">
<div class="content">
<asp:Literal ID="ltlBodyTitle" runat="server" /> 有这么一个控件
<asp:contentplaceholder
id="ContentPlaceHolder1"
runat="server" />
</div>
</form>
</body>
</html>
2.内容页如下
<%@ Page Language="C#" MasterPageFile="~/FindMaster.master" %>
<script runat="server">
void Page_Load()
{
if (!Page.IsPostBack)
{
Literal ltlBodyTitle =
(Literal)Master.FindControl("ltlBodyTitle"); 找到母版页上的控件
ltlBodyTitle.Text = "The Body Title";
}
}
</script>
<asp:Content
ID="Content1"
ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
Content, Content, Content, Content
<br />Content, Content, Content, Content
<br />Content, Content, Content, Content
<br />Content, Content, Content, Content
<br />Content, Content, Content, Content
</asp:Content>