阅读910 返回首页    go 阿里云 go 技术社区[云栖]


FindControl——对母版页使用FindControl方法

 
在内容页面,想对母版页的控件引用调用或者修改怎么办?

 

1.母版页如下

<%@ Master Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"https://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="https://www.w3.org/1999/xhtml" >
<head runat="server">

</style>
<title>Master</title>
</head>
<body>
<form runat="server">
<div >
<asp:Literal ID="ltlBodyTitle" runat="server" />  有这么一个控件
<asp:contentplaceholder

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>

 

最后更新:2017-04-02 22:16:00

  上一篇:go asp.net页面时间实时更新—UpdatePanel的应用
  下一篇:go asp.net利用一般处理程序下载和在线查看文档