Accessing Masterpage Variable

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
 
N

nahid

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/
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top