Object from Master Page?

  • Thread starter Thread starter Tarun Mistry
  • Start date Start date
T

Tarun Mistry

Hi all,

I have created an object within my Master Page. I would like to use this
object in my content pages. What would I need todo to achieve this?

Alternatively, what is the best way of handling a global object (in this
case, a shopping cart object).

Kind regards
Taz
 
I have created an object within my Master Page. I would like to use this
object in my content pages. What would I need todo to achieve this?

Alternatively, what is the best way of handling a global object (in this
case, a shopping cart object).

Well, it largely depends what type of object it is and how you've created
it.

The code behind a MasterPage is a class like pretty much everything else in
..NET, so you can create properties in your MasterPage which can be
referenced just like properties of any other class can be referenced.

There are hundreds of examples of this and similar things on Google, but you
might like to have a look at this:
http://west-wind.com/weblog/posts/5160.aspx which talks about some of the
issues with what you're trying to do - the site's recommendation to install
Web Application Projects is a good one...

Specifically on shopping carts, though, I've still not found anything
simpler than generics in Session...
 
I now realise this is possible using the <%@ MasterType
VirtualPath="~/MasterPage.master" %>
declaration.

However, is it possible to set this propery from within my .cs file as
opposed to the aspx file?

Thanks for any help
Taz
 
Specifically on shopping carts, though, I've still not found anything
simpler than generics in Session...

Hi Mark, many thanks for the reply.

I seem to now have it working, however, if I access the Master Page from
within the Page_Load of the content page, I get a null pointer exception. Is
this because the master page has not triggered its own Page_load event (this
is where my data is being set).

Please help.

Kind Regards
Taz
 
I seem to now have it working, however, if I access the Master Page from
within the Page_Load of the content page, I get a null pointer exception.
Is this because the master page has not triggered its own Page_load event
(this is where my data is being set).

Please help.

You can help yourself...

Set a breakpoint at the beginning of both events, and you'll soon see which
triggers first...
 
You can help yourself...
Set a breakpoint at the beginning of both events, and you'll soon see
which triggers first...

Good tip!

I come from a non IDE development background. I ought to get a handle on
these fine things that are available to me now! :)

Thanks

Taz
 
Back
Top