Global Variables / Masterpages (2.0)

  • Thread starter Thread starter Thiery Balser
  • Start date Start date
T

Thiery Balser

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
 
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"];
}
 

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

Back
Top