閱讀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利用一般處理程序下載和在線查看文檔