Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi all,

I am new to ASP.Net and C#.
I can't understand what is session.
For example, I can create a Session in aspx.cs page like...
C#
session.add("userid", txtusername); 

but I don't know, what is this and how can I get the user id in next page ?

Please help me.
Posted
v2

Dear Session is an object which contain information which you want to carry over
Suppose in your page1.aspx there is a test box whose ID is txt_user and a button
And if you want to use this test into next page lets say it is page2.aspx
You have to use like this
For a button click event
use session object
HTML
Session["your_session_variable_name"].ToString()=txt_user.Text;

and this will contains the text box value in session variable then you can use it in next page like this
HTML
String your_name=Session["your_session_variable_name"].ToString();

And now you can use this string till the session ends by default or you kill it
 
Share this answer
 
Comments
riteshsingh_jsr 17-Feb-13 12:23pm    
exactly......
007alok 18-Feb-13 3:10am    
So you found your answer appropriately ?
riteshsingh_jsr 18-Feb-13 6:15am    
yes
Reza Nabiloo 12-Mar-13 13:47pm    
thank u so much dear friend. i understand completly
You can add anything in a Session variable but you need to downcast it afterwards..

for example:


in ASP.NET
Session["object"] = anything

CODE BEHIND C#
anything x = (anything) Session["object"];
 
Share this answer
 
Hi,

In another page, Session["userid"].ToString() returns the session variable "userid".

More information about Session: Exploring Session in ASP.NET[^]

Hope this helps.
 
Share this answer
 
v3
Comments
Reza Nabiloo 12-Mar-13 13:49pm    
thank u so much dear friend.
Thomas Daniels 12-Mar-13 13:50pm    
You're welcome!
hii friend....

to take initial start with session then go to throw this link...

http://msdn.microsoft.com/en-us/library/75x4ha6s%28v=vs.100%29.aspx[^]

http://msdn.microsoft.com/en-us/library/03sekbw5%28v=vs.100%29.aspx[^]

thank you
 
Share this answer
 
Comments
Reza Nabiloo 12-Mar-13 13:47pm    
thank u so much dear friend.
Shubh Agrahari 13-Mar-13 10:35am    
ma pleasure...but bad luck its down voted by someone

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