Accessing controls of the Master Page from the Content Page
In my master page, i have a Label1 control. In the Page_Load event and if the page is not gone for postback event, in that situation, this Label1 is initialized with the day of the week. In this example, i have set the visibility of Label1 as false.
Now i want to access the Label1 control of the Master page from the Home.aspx.cs page. For that FindControl method is being used.
Page_Load event of the Content Page occurs before the Page_Load event of the Master Page. So if we write the following code in the Page_Load event of the Content page, it cannot access the control of the Master page, because by this time, Master Page_Load event hasn’t occurred. So it is better to write this code in Page_LoadComplete event of the Content Page, which comes just after the Page_Load event of the Master Page.
a. Page_Load Event of the Content Page
b. Page_Load Event of the Master Page
c. Page_LoadComplete Event of the Content Page.
On running the Home.aspx page, the following output comes, which shows that the Label1 control of the Master Page, has been accessed from the Content Page(Home.aspx)