the most cost effective way to persist page level objects in server

Discussion in 'ASP .Net' started by Ryan Liu, Jan 20, 2009.

  1. Ryan Liu

    Ryan Liu Guest

    Hi,

    What is the most cost effective way to persist page level objects in server
    side in asp.net?

    I know I can use session, but session is beyond page scope, seems a little
    bit waste to me, and it is bad to make it visible in other pages as well.

    Ocz I can use view state, but it is persisted though client, not in server
    side, which is also waste of network and serialization/de-serialization,
    and even more dangerous expose it to client.

    And other approach like form hidden fields, query string not to mention is
    even worse, plus I lost "object", have to deal with strings manually.

    Is there a nice, efficient, safe way/framework to just deal object in server
    side for just one particular page -- as long as the client stay in the same
    page?

    This will be very useful when deal data-binding/edit scenario.

    Thanks,
    Ryan
    Ryan Liu, Jan 20, 2009
    #1
    1. Advertising

  2. Ryan Liu

    George Guest

    I am not sure I understood the phrase "as long as the client stay in the
    same page"
    I have a feeling you do not realize the lifetime of the page object.

    Here is the live of the page
    1. Browser send request to the server.
    2. Page object is create
    3. Page object renders back HTML and it's buffered.
    4. Page object is destroyed and buffer sent back to the browser
    5. Browser renders HTML.

    So if you need to keep your object between 1 and 5 then use Context.Items
    collection.

    If you need to keep your object between browser request then you can use
    1. ViewState (you said you do not want to use it).
    2. ViewState that is kept on a server so it's not sent to browser. (Google
    it)

    George.


    "Ryan Liu" <> wrote in message
    news:...
    > Hi,
    >
    > What is the most cost effective way to persist page level objects in
    > server
    > side in asp.net?
    >
    > I know I can use session, but session is beyond page scope, seems a little
    > bit waste to me, and it is bad to make it visible in other pages as well.
    >
    > Ocz I can use view state, but it is persisted though client, not in server
    > side, which is also waste of network and serialization/de-serialization,
    > and even more dangerous expose it to client.
    >
    > And other approach like form hidden fields, query string not to mention is
    > even worse, plus I lost "object", have to deal with strings manually.
    >
    > Is there a nice, efficient, safe way/framework to just deal object in
    > server
    > side for just one particular page -- as long as the client stay in the
    > same
    > page?
    >
    > This will be very useful when deal data-binding/edit scenario.
    >
    > Thanks,
    > Ryan
    >
    George, Jan 20, 2009
    #2
    1. Advertising

  3. Ryan Liu

    Ryan Liu Guest

    I mean I need persist server object thought postbacks on the same page --
    that is beyond steps 1-5. A typical use case will be keep editing data in
    a data-binding page.

    If the user go to other page and come to the same page again, it is OK to
    lost sever objects. Indeed, when the user go to other pages, those server
    objects should be destroyed to save server sider resource.

    I guess if I need keep object between 1-5, I can but I don't even need to
    use Context.Items, I can just add a new attribute to current aspx Page .

    Thanks,
    Ryan


    "George" <> wrote in message
    news:...
    >I am not sure I understood the phrase "as long as the client stay in the
    >same page"
    > I have a feeling you do not realize the lifetime of the page object.
    >
    > Here is the live of the page
    > 1. Browser send request to the server.
    > 2. Page object is create
    > 3. Page object renders back HTML and it's buffered.
    > 4. Page object is destroyed and buffer sent back to the browser
    > 5. Browser renders HTML.
    >
    > So if you need to keep your object between 1 and 5 then use Context.Items
    > collection.
    >
    > If you need to keep your object between browser request then you can use
    > 1. ViewState (you said you do not want to use it).
    > 2. ViewState that is kept on a server so it's not sent to browser. (Google
    > it)
    >
    > George.
    >
    >
    > "Ryan Liu" <> wrote in message
    > news:...
    >> Hi,
    >>
    >> What is the most cost effective way to persist page level objects in
    >> server
    >> side in asp.net?
    >>
    >> I know I can use session, but session is beyond page scope, seems a
    >> little
    >> bit waste to me, and it is bad to make it visible in other pages as well.
    >>
    >> Ocz I can use view state, but it is persisted though client, not in
    >> server
    >> side, which is also waste of network and serialization/de-serialization,
    >> and even more dangerous expose it to client.
    >>
    >> And other approach like form hidden fields, query string not to mention
    >> is
    >> even worse, plus I lost "object", have to deal with strings manually.
    >>
    >> Is there a nice, efficient, safe way/framework to just deal object in
    >> server
    >> side for just one particular page -- as long as the client stay in the
    >> same
    >> page?
    >>
    >> This will be very useful when deal data-binding/edit scenario.
    >>
    >> Thanks,
    >> Ryan
    >>

    >
    Ryan Liu, Jan 20, 2009
    #3
  4. Ryan Liu

    George Guest

    You almost right about Context.Items. Sometimes you need to share object
    between 2 separate UserControls for example or HttpHandler and Page object.
    And the easies way is to use Context.Items then.

    But since you need to keep that object between Postbacks then use ViewState.
    That is what it's there for. If you do not like to send it back to the
    browser look up the link Mark provided about keeping ViewState on the
    server.

    George.


    "Ryan Liu" <> wrote in message
    news:...
    >I mean I need persist server object thought postbacks on the same page --
    >that is beyond steps 1-5. A typical use case will be keep editing data in
    >a data-binding page.
    >
    > If the user go to other page and come to the same page again, it is OK to
    > lost sever objects. Indeed, when the user go to other pages, those server
    > objects should be destroyed to save server sider resource.
    >
    > I guess if I need keep object between 1-5, I can but I don't even need to
    > use Context.Items, I can just add a new attribute to current aspx Page .
    >
    > Thanks,
    > Ryan
    >
    >
    > "George" <> wrote in message
    > news:...
    >>I am not sure I understood the phrase "as long as the client stay in the
    >>same page"
    >> I have a feeling you do not realize the lifetime of the page object.
    >>
    >> Here is the live of the page
    >> 1. Browser send request to the server.
    >> 2. Page object is create
    >> 3. Page object renders back HTML and it's buffered.
    >> 4. Page object is destroyed and buffer sent back to the browser
    >> 5. Browser renders HTML.
    >>
    >> So if you need to keep your object between 1 and 5 then use Context.Items
    >> collection.
    >>
    >> If you need to keep your object between browser request then you can use
    >> 1. ViewState (you said you do not want to use it).
    >> 2. ViewState that is kept on a server so it's not sent to browser.
    >> (Google it)
    >>
    >> George.
    >>
    >>
    >> "Ryan Liu" <> wrote in message
    >> news:...
    >>> Hi,
    >>>
    >>> What is the most cost effective way to persist page level objects in
    >>> server
    >>> side in asp.net?
    >>>
    >>> I know I can use session, but session is beyond page scope, seems a
    >>> little
    >>> bit waste to me, and it is bad to make it visible in other pages as
    >>> well.
    >>>
    >>> Ocz I can use view state, but it is persisted though client, not in
    >>> server
    >>> side, which is also waste of network and
    >>> serialization/de-serialization,
    >>> and even more dangerous expose it to client.
    >>>
    >>> And other approach like form hidden fields, query string not to mention
    >>> is
    >>> even worse, plus I lost "object", have to deal with strings manually.
    >>>
    >>> Is there a nice, efficient, safe way/framework to just deal object in
    >>> server
    >>> side for just one particular page -- as long as the client stay in the
    >>> same
    >>> page?
    >>>
    >>> This will be very useful when deal data-binding/edit scenario.
    >>>
    >>> Thanks,
    >>> Ryan
    >>>

    >>

    >
    George, Jan 20, 2009
    #4
  5. Ryan Liu

    bruce barker Guest

    Re: the most cost effective way to persist page level objects inserver

    saving viewstate on the server just stores it in session, along with all
    control properties. in general this is a poor design, your pages should
    be stateless. store only whats needs, also viewstate should be turned off.

    -- bruce (sqlwork.com)

    Mark Rae [MVP] wrote:
    > "George" <> wrote in message
    > news:...
    >
    >> If you need to keep your object between browser request then you can use
    >> 1. ViewState (you said you do not want to use it).
    >> 2. ViewState that is kept on a server so it's not sent to browser.
    >> (Google it)

    >
    > The basic technique is simple enough:
    > http://adidrumea.blogspot.com/2005/11/aspnet-server-side-viewstate.html
    >
    > Depending on how a web app is constructed, this can make a dramatic
    > difference...
    >
    >
    bruce barker, Jan 20, 2009
    #5
    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. Harry
    Replies:
    1
    Views:
    401
    Joe Fallon
    Apr 13, 2004
  2. Usenet  User
    Replies:
    5
    Views:
    528
    Steve C. Orr [MVP, MCSD]
    Mar 24, 2005
  3. Matt Priest
    Replies:
    5
    Views:
    301
    Thomas Matthews
    Oct 23, 2003
  4. pabbu
    Replies:
    8
    Views:
    701
    Marc Boyer
    Nov 7, 2005
  5. Elaine
    Replies:
    0
    Views:
    337
    Elaine
    Nov 27, 2007
Loading...

Share This Page