Click here to Skip to main content
15,915,513 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi Friends,

I am having small database project in which It has various users login and need to show their related data depends on their users data. i.e that normal mail application for that i need to trace out the which user is currently login and use his id through out until he logs out for this session key variable is better i thought but i dont know how to use it.

Please friends post how to use a session variable and where should i need to initialize the variable so that it is visible through out the program and please provide a complete procedure.


Thanks in Advance
Ganesh Kumar Poosarla
Posted

you no need to initialize the Session Key.

when user log-in in application at that time you can set some session variable
i.e
Session["Variable Name"]= value


You can create a multiple session like, i.e Session["UserName"],Session["UserID"] etc..

Once you set the session variable then you can user it in whole application.

and When User will close the browser or logout from the application then you can clear the session.

you can manage Session in different ways in asp.net
Session Variable
 
Share this answer
 
Yes nigam,

We can do that..

For example if you want to get TextBox value in Session variable..

Session["UserName"] = txtUserName.text

and if you want to get details of user from database

you can write this query..

Select * from userMaster where username=Session["UserName"].ToString();

enjoy...!
 
Share this answer
 
Hi Nigam Patel

Thanks for your answer
Can we directly assign the text box value to a session variable and can we retrieve the data from database using the Session Variable.

Thanks in Advance
Ganesh Kumar Poosarla.
 
Share this answer
 
Thanks Ravituvar for your valuble answer...

It helps me a lot....
 
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