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

Discussion in 'ASP .Net' started by mato, Feb 17, 2004.

  1. mato

    mato Guest

    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.
     
    mato, Feb 17, 2004
    #1
    1. Advertising

  2. mato

    mato Guest

    well, the problem was solved by restarting aspnet_wp.exe process.
    hmm......

    "mato" <> wrote in message
    news:%238tf$...
    > 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.
    >
    >
     
    mato, Feb 17, 2004
    #2
    1. Advertising

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. Tony Cheng
    Replies:
    1
    Views:
    8,216
    Juan T. Llibre
    Feb 24, 2006
  2. Replies:
    1
    Views:
    663
    Jules
    Aug 18, 2005
  3. Jess
    Replies:
    4
    Views:
    444
  4. news.aon.at
    Replies:
    11
    Views:
    649
    Ian Collins
    Jan 29, 2011
  5. Sound
    Replies:
    2
    Views:
    448
    Randy Webb
    Sep 28, 2006
Loading...

Share This Page