Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello all

 

Having just started learning about C# and ASP.NET, my background being C/UNIX, I wanted to check my understanding regarding how data can be preserved from one web page to another... would you mind confirming I've got my head around this properly?! Much appreciated!! Thanks for the site.

 

Assume you have webform1 and webform2, and webform1 has (say) a textbox (e.g. called Fred) whereby the user can enter some text.

 

I think this could be accessed by the code in webform1.aspx.cs, either by using the Request.Form structure, or by referring to Fred directly, as it is declared within webform1.aspx.cs

 

If you then Server.Transfer over to webform2, and wish to access the contents of Fred, I have reached the conclusion that I would need to write the contents of Fred into a Session variable during execution of webform1, and then reference this in webform2.

 

The Request.Form structure is no good, because that will reflect webform2.

 

Attempts to access Fred using Webform1.Fred from Webform2 don't work (compilation error - "inaccessible due to protection level"), so I take it from this that the values from the web controls in webform1 are not preserved or cannot be accessed.

 

My conclusion is for any values I wish to preserve, I need to store within the session structure.

 

Am I about right?

Many thanks

Sparkle

  • *Experts*
Posted (edited)

That is correct. Because the Internet was designed as a

stateless environment, there is no uniform way (between HTML,

PHP, ASP, etc.) to maintain state (except for maybe cookies).

 

If the data in "Fred" is not security-concious, you could also pass

the value into the QueryStrings of the next page. Then, when

people copied and pasted the URL, the state would be

maintained. You don't want to do this if the data is too large.

 

For example: /mypage.aspx?Fred=woohoo&Ethel=yeahbaby

 

You can use cookies if you're storing the data for a long

time, and want to keep it when the user returns to the site.

 

So it's up to you! Session variables, cookies, and query strings all

have different qualities, so choose wisely, grasshopper. :)

 

[edit]Click me! <- Robby indirectly solves all your confusion[/edit]

Edited by Bucky

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...