I'm confused (Viewstate and Context)

H

Hugo Flores

Hi,

I'm trying to pass information between pages. I'm trying to avoid using
QueryString and Session variables. I saw somewhere that I could use
contxt.Items.Add (combined with Server.Transfer) to store my
information and send it to another page. Some of my pages, either go to
other pages, or postback depending on the situation. When I began to
get confused was when I saw that I needed to store my variables on the
viewstate if I wanted to postback. So any answers to the next questions
could really help me understand all of this.

1. Isn't the context stored on the viewstate?
2. If that's the case, what would be the use of using the context
object if I'm going to end up storing everything on the viewstate to
get the info on postback, and also wouldn't I be duplicating my
viewstate when I and I reset my context variables, to do
Server.Transfer, because my viewstate already has that info.
3. What would be the best way to pass information, I'm only trying to
persist three variables, nothing more than that.

I know I must probably misunderstood the context object or the
viewstate. I really need somebody to get me out of my confusion.

Thanks
 
L

Lucas Tam

1. Isn't the context stored on the viewstate?

No, context items are sent as part of the server.transfer. After the
server.transfer, context items are disposed.
2. If that's the case, what would be the use of using the context
object if I'm going to end up storing everything on the viewstate to
get the info on postback, and also wouldn't I be duplicating my
viewstate when I and I reset my context variables, to do
Server.Transfer, because my viewstate already has that info.

You can't send viewstate between pages.
3. What would be the best way to pass information, I'm only trying to
persist three variables, nothing more than that.

Page A, use httpcontext to send the variables to Page B. In Page B, save
the variables to a viewstate variable which can be used during a
postback.

Or, use a session variable.

Or use a querystring.

There's nothing wrong with using a querystring - if you're querying
against public data (i.e. non secured data).
 

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

Similar Threads

Confused...? 2
I'm new 0
I'm tempted to quit out of frustration 1
viewstate 0
Confused by ViewState 5
Problem with control and ViewState 3
Tables and ViewState 1
ViewState v Session - Confused 6

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top