If the control to be accessed is inside the contentplaceholder control on the master page, you must first obtain the reference to the contentplaceholder control, and then call its findcontrol method to obtain reference to the control.
In the page_load method on the Content Page, set the text attribute of the label control on the nested template page:
Obtain the reference of the contentplaceholder control on the main template page, and then obtain the reference of the control to be modified.
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
Contentplaceholder Pcontent = (contentplaceholder) page. Master. Master. findcontrol ("Main ");
If (Pcontent! = NULL)
{
Label plbltitle = (Label) Pcontent. findcontrol ("lbl_title ");
If (plbltitle! = NULL)
{
Plbltitle. Text = "my title ";
}
}
}
}
Appendix:
Main template page:
<% @ Master language = "C #" autoeventwireup = "true" codefile = "masterpage. master. cs" inherits = "master_masterpage" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> untitled page </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: contentplaceholder id = "Main" runat = "server">
</ASP: contentplaceholder>
</Div>
</Form>
</Body>
</Html>
Nested template page:
<% @ Master language = "C #" masterpagefile = "~ /Master/Default. Master "autoeventwireup =" true "codefile =" combines. master. cs "inherits =" master_combines "%>
<Asp: Content ID = "content_combine" contentplaceholderid = "Main" runat = "server">
<Asp: Label id = "lbl_title" runat = "server" text = ""> </ASP: Label>
<Asp: contentplaceholder id = "combine" runat = "server">
</ASP: contentplaceholder>
</ASP: content>
Content Page:
<% @ Page Language = "C #" masterpagefile = "~ /Master/combines. Master "autoeventwireup =" true "codefile =" stationcombine. aspx. cs "inherits =" _ default "Title =" untitled page "%>
<% @ Mastertype virtualpath = "~ /Master/combines. Master "%>
<Asp: Content ID = "content1" contentplaceholderid = "combine" runat = "server">
</ASP: content>