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 ();
========================================================== ==========
1. How to log on to the backend Code Set and retrieve the properties of the subcontrol in the user control?
Usercontrol c = (usercontrol) findcontrol ("yourusercontrolid ");
Textbox TB = (textbox) C. findcontrol ("yourtextboxidinyourusercontrol); TB. Text =" 123 ";
2. How to set and obtain the attributes of the user control in the background?
Youruser controlid. property1 = "123 ";
Obtain controls in user controls on the template page
Control_left2 c = (control_left2) master. findcontrol ("left2_1 ");
(Label) C. findcontrol ("label1"). Text = model. companypoint. tostring ();
Simple finishing version.