Accessing Masterpage Variable

Discussion in 'ASP .Net Web Controls' started by Al, Jun 30, 2007.

  1. Al

    Al Guest

    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
    Al, Jun 30, 2007
    #1
    1. Advertising

  2. Al

    nahid Guest

    On Jun 30, 10:13 am, "Al" <> wrote:
    > 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, Jun 30, 2007
    #2
    1. Advertising

  3. Al

    Sivakumar G Guest

    "nahid" wrote:

    > On Jun 30, 10:13 am, "Al" <> wrote:
    > > 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/
    >
    >


    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
    Sivakumar G, Jul 1, 2007
    #3
  4. Al

    marss Guest

    nahid wrote:

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


    .... or cast Page.Master to specific master page.
    ((Main)Page.Master).objDT = ...

    Regards, Mykola
    http://marss.co.ua
    marss, Jul 2, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QWxleCBNYWdoZW4=?=

    MasterPage -> Page -> MasterPage Code Access

    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Apr 10, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    7,886
    Steven Cheng[MSFT]
    Apr 14, 2006
  2. ThunderMusic
    Replies:
    2
    Views:
    445
    Gregory Gadow
    Sep 27, 2006
  3. Randy Smith
    Replies:
    9
    Views:
    421
    Mark Rae
    Apr 14, 2007
  4. mr t
    Replies:
    0
    Views:
    400
  5. Torben Laursen
    Replies:
    4
    Views:
    572
    clintonG
    Mar 15, 2008
Loading...

Share This Page