Accessing controls of the Master Page from the Content Page

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.

Master.master

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.
I mean:
a. Page_Load Event of the Content Page
b. Page_Load Event of the Master Page
c. Page_LoadComplete Event of the Content Page.

Home.aspx.cs

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)

Advertisements

About kakani santosh kumar

Working as Software Engineer in Prithvi Information Solutions having 3 years of Experience in Dotnet Framework ranging from 1.1 to 3.5
This entry was posted in Articles, Coding, Database, Programming and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s