Question : C# - Variable values being nulled out between code-behind and inline ASPX code.

Ok this is a tough one to describe -

I have a homebrew CMS.  Items in the CMS are revisioned.  Revisioned items have a LiveRevision property.

Whenever a page that is responsible for rendering an Item is created, it is derived from a base class "ItemHandler" which is derived from UI.Page.   The ItemHandler class populates an Item object based on the URI and Querystring,  and then exposes the Item object the inheriting page for further processing and rendering,

An The Item's LiveRevision property is setup as such:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
private object _liveRevision;

public object LiveRevision  
{ 
   get { 
     if (_liveRevision == null) _liveRevision = GetLiveRevision();
     return _liveRevision;
    }
}


The effect is that, for an item's life cycle, the _liveRevision object should only be created once.  Subsequent calls to LiveRevision property will return the cached _liveRevision object.


This all works, except for the transition from code-behind to .aspx inline c# code.


for example, the following will result in only 1 call to the GetLiveRevision() method inside the LiveRevision property defined above.

Code Behind:
1:
2:
3:
4:
5:
6:
{
   string x = Item.LiveRevision.Title;
   string y = Item.LiveRevision.Summary;
   string z = Item.LiveRevision.Date.ToString();
}


The issue comes in to play on the ASPX side.  A line as such, will produce another call to the "GetLiveRevision()" method, even though it should have already been cached by the code-behind.

1:
2:
3:
<%= Item.LiveRevision.Title %>
<%= Item.LiveRevision.Summary %>


This is NOT the desired behavior.  Can anyone explain what might be going on here?  I imagine that for the page's life cycle, only a single call to GetLiveRevision should be made, all others returning the cached private variable.

Thanks

Answer : C# - Variable values being nulled out between code-behind and inline ASPX code.

http://www.ammara.com   >>> DBPix ...

You might want to consider this ... and I can totally vouch for this program.  

It does all the work for you. Examples show how to add a simple 'control' panel to Load, Save, Zoom In/Out, Size To Fit and much more.  AND ... virtually eliminates BLOAT associated with storing images in an Access MDB. I have 3 clients who sell commercial run-time products that use DBPix.

Note. I have no connection with DBPix ... except I have used it many times ...

mx


Random Solutions  
 
programming4us programming4us