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

R

Ryan Liu

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
 
G

George

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.
 
R

Ryan Liu

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
 
G

George

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.
 
B

bruce barker

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)
 

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,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top