Session backed properties

nakor77

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.

185 Views
About the Author
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;
	}
}
Member Avatar
LastMitch

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.