We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,171 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Session backed properties

0
By Jonathan Cherryhomes on Aug 18th, 2012 4:24 am

This snippet will allow you to easily work with session variables in your applications. This example is using a string type but it works the same for any data type, you would just need to change the default return value from string.Empty to something more appropriate.

public string PropertyName
{
	get
	{
		object temp = Session["PropertyName"];
		// Returns an empty string if the session variable is null
		// otherwise it casts the session variable to a string and returns it
		return temp == null ? string.Empty : temp as string;
	}
	set
	{
		Session["PropertyName"] = value;
	}
}

Sometimes an image would be nice or echoing out the session letting people know is working or not.

Maybe included this:

<% Response.Write Session.CodePage(=PropertyName) %>

I don't know you can corrected my Response.Write function.

LastMitch
Industrious Poster
4,177 posts since Mar 2012
Reputation Points: 132
Solved Threads: 335
Skill Endorsements: 45

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0555 seconds using 2.66MB