Global Variables / Masterpages (2.0)

Discussion in 'Microsoft ASP .NET' started by Thiery Balser, Aug 9, 2006.

  1. Hi Everybody!


    I'm stuck with the following problem:

    I have a couple of pages which has all the same 'header', i.e. some common
    elements. So far I realized that the best thing would be to use master
    pages. This is all fine and works.

    Now, there are certain variables stored in the session object which I would
    like to use in the other pages. What I would like to do is to initialize the
    variables, assign values to them in the Page_Load of the MasterPage and then
    use in the other pages (outside the masterpage, i.e., in the pages which use
    the MasterPage). Is there any smart way to do this?



    Thank you very much in advance,



    Thiery
     
    Thiery Balser, Aug 9, 2006
    #1
    1. Advertisements

  2. Thiery Balser

    Guest Guest

    You just described a "smart way". - Try and see how it works.
    Peter

    --
    Co-founder, Eggheadcafe.com developer portal:
    http://www.eggheadcafe.com
    UnBlog:
    http://petesbloggerama.blogspot.com




    "Thiery Balser" wrote:

    > Hi Everybody!
    >
    >
    > I'm stuck with the following problem:
    >
    > I have a couple of pages which has all the same 'header', i.e. some common
    > elements. So far I realized that the best thing would be to use master
    > pages. This is all fine and works.
    >
    > Now, there are certain variables stored in the session object which I would
    > like to use in the other pages. What I would like to do is to initialize the
    > variables, assign values to them in the Page_Load of the MasterPage and then
    > use in the other pages (outside the masterpage, i.e., in the pages which use
    > the MasterPage). Is there any smart way to do this?
    >
    >
    >
    > Thank you very much in advance,
    >
    >
    >
    > Thiery
    >
    >
    >
     
    Guest, Aug 9, 2006
    #2
    1. Advertisements

  3. Sure, creating public properties on your master page, and use the MasterType
    directive.

    So in your page, if you do:

    <%@ masterType VirtualPath="~/template/main.master" %>

    you can then access your master's properties in a strongly-typed fashion in
    your page

    int userId = Master.UserId;

    Karl

    ur master would look soemthing like:

    private int _userId;
    public int UserId
    {
    get { return _userId; }
    }

    Page_Load(...)
    {
    _userId = (int)Session["userId"];
    }

    --
    http://www.openmymind.net/
    http://www.codebetter.com/


    "Thiery Balser" <> wrote in message
    news:44d983d0$...
    > Hi Everybody!
    >
    >
    > I'm stuck with the following problem:
    >
    > I have a couple of pages which has all the same 'header', i.e. some common
    > elements. So far I realized that the best thing would be to use master
    > pages. This is all fine and works.
    >
    > Now, there are certain variables stored in the session object which I
    > would like to use in the other pages. What I would like to do is to
    > initialize the variables, assign values to them in the Page_Load of the
    > MasterPage and then use in the other pages (outside the masterpage, i.e.,
    > in the pages which use the MasterPage). Is there any smart way to do this?
    >
    >
    >
    > Thank you very much in advance,
    >
    >
    >
    > Thiery
    >
     
    Karl Seguin [MVP], Aug 9, 2006
    #3
    1. Advertisements

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. Wayne

    Global variables on par with ASP's global.asa

    Wayne, Nov 5, 2003, in forum: Microsoft ASP .NET
    Replies:
    2
    Views:
    312
    Wayne
    Nov 11, 2003
  2. neverstill

    P. Wilson's MasterPages

    neverstill, Dec 10, 2003, in forum: Microsoft ASP .NET
    Replies:
    2
    Views:
    350
    neverstill
    Dec 11, 2003
  3. Nick Wouters
    Replies:
    5
    Views:
    305
    Flinky Wisty Pomm
    May 8, 2006
  4. tool
    Replies:
    1
    Views:
    169
    Brock Allen
    Jun 11, 2006
  5. JohnE

    masterpages with masterpages

    JohnE, Dec 7, 2009, in forum: Microsoft ASP .NET
    Replies:
    1
    Views:
    219
    Hillbilly
    Dec 8, 2009
Loading...

Share This Page