is this possible? string field member already set on page init

M

mato

this is what i experienced in my web application and i realy do not
understand.

this is my web page class behind
public class MyWebPage : System.Web.UI.Page
{
//some page controls
.....

//this is problematic field, it is meant to be internal server cache
variable for DocumentClass property
private string m_searchDocumentClass = null;
//property
protected string DocumentClass
{
get
{
if( m_searchDocumentClass == null )
{
if( searchObject != null )
{
m_searchDocumentClass =
searchObject.GetDocumentClass( );
}
else
{
m_searchDocumentClass = "Default";
}
}
return m_searchDocumentClass;
}
}

protected SearchObject searchObject
{
get
{
return ( SearchObject )Session[ "SearchObject" ];
}
}

//some methods
.....

//init
protected override void OnInit( System.EventArgs e )
{
if( !Page.IsPostBack )
{
//some first time init stuff
InitSearchObject();
}

//some controls init stuff
}
}

for the first time everything is ok. InitSearchObject is called.
m_searchDocumentClass is null. then it is set to "Default".
purpose of m_searchDocumentClass is to cache it for server page life only.
so one does not have to search for this stuff
everytime it is needed.
then controls are created and page is sent to client.
second time when post back occurs ( for example someone has clicked some
button on the page ), in page init m_searchDocumentClass
is already set, and i am realy, realy confused about it, because i expect it
to be null.
can this happen? and if yes, why, when and what properties or whatever is
needed to accomplish this situation?

ps. the only reference to m_searchDocumentClass is realy in DocumentClass
property getter.
i looked throug my code several times, searched for occurences of
m_searchDocumentClass, and only place it is set is in DocumentClass
property getter.

thank you for any comment, help, opinion or anything.
 

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

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top