How to access master page variable from child pages in ASP.Net using C#?

Asp.net using C#

Posted by iks on 1/14/2015 11:10:36 AM

Declare a variable in master page file MasterPage.master.cs as Public.

e.g:

public string bgImg;

Now in MasterPage.master file use this variable as:

<%= bgImg %>

Go to your child page for example in default.aspx add the following Tag:

<%@ MasterType TypeName="MasterPage" %>

Now in cs file of default page set its value:

Master.bgImg = "blogpost-bg.jpg";

 

Now you are all set with your code.

 


Comments

Please leave your comment here!