Share via


HttpContext.Current.Items for passing values

Question

Monday, December 1, 2008 7:17 AM

Hi,

When passing a value from one .aspx page to another in c# is this a good way to pass the value:

HttpContext.Current.Items["CustomerId"] = profile.CustomerId.ToString();

and then retrieve it from the HttpContext.Current.Items collection on the other page?

I dont want the user to see the values on the url or be able to manipulate them.

Thanks for any suggestions.

All replies (7)

Monday, December 1, 2008 8:15 AM ✅Answered

Hi,

you can use Session-Variables

set in one page

Session["CustomerID"] = profile.CustomerId.ToString();

get in another page

string CustomerID = Session["CustomerID"].ToString();


Monday, December 1, 2008 8:27 AM ✅Answered

Please check this http://msdn.microsoft.com/en-us/library/system.web.ui.page.previouspage.aspx.


Monday, December 1, 2008 8:48 AM ✅Answered

Hi,

Maybe this should help's : http://blog.sb2.fr/post/2008/11/29/Get-Previous-Page-Control-Values-after-Cross-Page-Posting.aspx


Monday, December 1, 2008 10:08 AM ✅Answered

The Items collection of the HttpContext is a great way to pass along data that is needed during a single request, but if you need to information to live beyond a single request the Items collection is no help (it is discarded after the request).

I have a couple articles that might help: Design Considerations for Cross Page Post Backs and an older article on HttpContext.Items collection.


Monday, December 1, 2008 10:12 AM ✅Answered

Here's a few more options:

http://dotnetslackers.com/Community/blogs/haissam/archive/2007/11/26/ways-to-pass-data-between-webforms.aspx


Tuesday, December 2, 2008 7:59 AM ✅Answered

 Just from personal experience I would be wary of using HttpContext.Items.  I've used it, and sometimes it has become problematic.  It becomes a 'Request Global' variable with all the problems that global variables have. 


Monday, December 1, 2008 9:37 AM

Thanks, these are some good suggestions.

Do you guys have a view on when to use the httpcontext then and when not to? Is wrong to use this? Also the previouspage property is only valid for .net 3.5 I see?

Thanks Again