Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 10th, 2008, 04:22 PM
Registered User
 
Join Date: Apr 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Assign Session variable from view or controller

Hi

Can I assign a session variable from a controller class? I tried assigning from controller class and am getting error. I would like to retrieve values from database and assign those values to object attributes and assign each object into session variable so that I can access those object values from any class. Please help me if I am wrong.

Thanks

 
Old April 10th, 2008, 11:38 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The HttpContext class has a static property Current which will get you access to just about anything on the current request you'd need apart from the actual page class. Thus you could do this:

System.Web.HttpContext.Current.Session["MyObject"] = myObject;

Keep in mind that you might want to do a not null check on Current in the event the code is called from a non web context if that's likely to happen.

-Peter
peterlanoie.blog
 
Old April 11th, 2008, 09:37 AM
Registered User
 
Join Date: Apr 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you so much. It worked.







Similar Threads
Thread Thread Starter Forum Replies Last Post
assign XSLT variable to a wml variable arunagottimukkala XSLT 2 October 19th, 2007 05:15 AM
assign javascript variable to asp variable manjunath_c_k Classic ASP Basics 1 September 14th, 2006 07:35 AM
How To Assign Value To Session Using Javascript janice.koay Classic ASP Professional 1 May 9th, 2006 12:59 AM
Model View Controller gpartin33324 Java GUI 0 October 4th, 2004 04:00 PM
Create "View" and Assign Permission phungleon SQL Server 2000 3 June 18th, 2004 11:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.