RSS

If its important add it to a session

29 Feb

So, allot of time I see a variable that is the exact same used many times throughout a web page. This in itself is not a problem but actually very common when you work in a web environment with business web apps. The problem comes in when you constantly retrieve that value over and over instead of storing it in the session so lets say when i log in i go to a page that has me select the client company who’s data I wish to manipulate and then move on. This is a variable used in 5 pages and if i wish to change it i have to go and use a dropdown or some other control w/e it stays the same until I change it in a single master control.
This should be saved in a session variable I should not have to set it every time i load a new variable and I should only have to select a new company when I actually want to change my client company. So guys learn to do this you may not be a webdev but at least understand the basic concept.

example of saving a value

Session["testcompany"] = ddlCompany.SelectedValue;

example of saving a whole object

DataTable mycompany = new DataTable();

//fill the data table with you company info

Session["mycompany"] = mycompany;

now until the user terminates the session the information for the selected company and the actual company selected is saved.

Advertisements
 
Leave a comment

Posted by on February 29, 2012 in ASP.Net, C#

 

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: