天天看點

FindControl——對母版頁使用FindControl方法

在内容頁面,想對母版頁的控件引用調用或者修改怎麼辦?

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

</asp:content>

繼續閱讀