Accessing Masterpage Variable

  • Thread starter Thread starter Al
  • Start date Start date
A

Al

Hi,

I'm working on a site with master page with a few more pages that will show
up in the content placeholder. The master page has a few variables as
follows:

public partial class Main : System.Web.UI.MasterPage
{
DataTable objDT;
DataRow objDR;

. . . . .
}

On another page (Default.aspx), whcih is going to be showing up in the
master page content place holder, I have the following as the first line:

<%@ Page Language="C#" MasterPageFile="~/Main.Master"
AutoEventWireup="true" CodeBehind="Products.aspx.cs"
Inherits="onlineStore.Products" Title="Untitled Page" %>

I want to access the objDT data-table from the Master page from this
Default.aspx page, but I cannot seem to do that. It gives me an error objDT
does not exist in the current context.

I tried doing something like Master.objDT, but there is nothing like that,
and I still get an error.

Any ideas how I can resolve this?

Thanks!
Al
 
Hi,

I'm working on a site with master page with a few more pages that will show
up in the content placeholder. The master page has a few variables as
follows:

public partial class Main : System.Web.UI.MasterPage
{
DataTable objDT;
DataRow objDR;

. . . . .
}

On another page (Default.aspx), whcih is going to be showing up in the
master page content place holder, I have the following as the first line:

<%@ Page Language="C#" MasterPageFile="~/Main.Master"
AutoEventWireup="true" CodeBehind="Products.aspx.cs"
Inherits="onlineStore.Products" Title="Untitled Page" %>

I want to access the objDT data-table from the Master page from this
Default.aspx page, but I cannot seem to do that. It gives me an error objDT
does not exist in the current context.

I tried doing something like Master.objDT, but there is nothing like that,
and I still get an error.

Any ideas how I can resolve this?

Thanks!
Al


hi,
put this line in your Products.aspx page
<%@ MasterType VirtualPath="~/Main.Master.master" %>

hope this help

nahid
http://nahidulkibria.blogspot.com/
http://kaz.com.bd/
 
nahid said:
hi,
put this line in your Products.aspx page
<%@ MasterType VirtualPath="~/Main.Master.master" %>

hope this help

nahid
http://nahidulkibria.blogspot.com/
http://kaz.com.bd/

Hi Al,

You will also need to add public modifier to member variable objDT and
objDR in the master page class defenition for them to be accesible from the
content pages, after importing the master page type into the content pages as
suggested by Nahid.

HTH

Siva
 
Back
Top