Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using sessions in asp.net

I would like the data that i enter in a text box on pageA to be accessable on pageB

eg: User enters their name in text box on page A

page B says Hello (info they entered in text box)

I heard this can be accomplished by using a session but i don't know how.

can someone please tell me how to setup a session and how to store data in it? Thank you!


1 Answers

Session["valueName"]=value; 

or

Session.Add("valueName",Object);

And You can retrieve the value in label (for Example) By

/*if String value */     
Label1.Text=Session["valueName"].ToString();

or

Label1.Text=Session.item["valueName"].ToString();

And also You can remove the session by;

/*This will remove what session name by valueName.*/
 Session.Remove( "valueName"); 

/*All Session will be removed.*/ 
Session.Clear(); 
like image 63
Syed Tayyab Ali Avatar answered Feb 16 '26 01:02

Syed Tayyab Ali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!