You can use either of the following methods to obtain the content of a master page:
1. Use findcontrol to find the control ID
In this event ~ Because in page_load, the content page is first loaded and then the master page is loaded.
Protected void page_loadcomplete (Object sender, eventargs E)
{
Label2.text = "the current time is" + (master. findcontrol ("label1") as label). text;
If (request. querystring ["ID"] = "dy ")
{
(MASTER. findcontrol ("image1") as image). imageurl = "~ /Images/ml0069.jpg ";
}
}
2. Use strong references
<% @ Page Language = "C #" masterpagefile = "~ /Masterpage. Master "autoeventwireup =" true "codefile =" default2.aspx. cs "inherits =" default2 "Title =" untitled page "%>
<% @ Mastertype virtualpath = "~ /Masterpage. Master "%>
You can then define public attributes or methods on the master page.
Public String GetUserName ()
{
Return page. User. Identity. Name;
}
Call
Label1.text = "welcome" + master. GetUserName ();
For Dynamic Master loading ~ The ASP. net2.0 Development Guide of instructor haogang is introduced ~ There are alsoCode~ But I personally think it is not convenient ~ So I didn't post it ~ Simple changes can be implemented through the above method