Click here to Skip to main content
15,905,776 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Am using windows application using c#. How to set session? i typed Session["Time"]=DateTime.Now; .But the error is coming like this.

The name session does not exist in the current context.

Can anyone help me. Am new to this technology.
Posted
Updated 30-Jul-11 20:55pm
v3

Sessions do not exist in Winforms applications - only in web based.

What you have to do depends on what you are trying to achieve: Configuration settings preserve data from run to run, but within an application, data is preserved for the duration of the run, provided it does not go out of scope and/or get Disposed.
So class level variables within your form will be preserved from button press to button press, unlike web based.

What are you trying to achieve?
 
Share this answer
 
Comments
Aswathi Narayan 31-Jul-11 3:22am    
I need to Print a an Order consist of two fields Item and Quantity. In form1 gridview i entered the item and quantity. i need to print this form like a bill. how can i do this? Can u help me?
OriginalGriff 31-Jul-11 3:33am    
The best way is to use a PrintDocument: MSDN has an example. http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument(v=VS.90).aspx
You cannot. There are no equivalents either. So you need to implement your own logic using a temporary store (database etc) to do this.
 
Share this answer
 
Session object is web based, so here since your application is Desktop application i would suggest you to have the data you want consistency for as static. Static variables are available throughout the alive thread.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900