Hello,

I am used to VB.Net, and I recently starting using ASP.Net 2.0 with VB.Net. What I do not understand is how to keep my variables. Everytime the page goes back to the server I lose information. It gets lost. I've looked everywhere and read a lot of information and I am just not understanding what to do to keep my variables. For example I am trying to do a calculation in ASP.Net. I put a number in a textbox. Then I press a button and try to enter the next number, but the first number is gone. I've read about Session variables and such, but I do not understand how to use them or where to put them in the code. Can someone please explain to me how to keep variables and maybe give an example?

Thank you,
Jesi

To store value in a session variable
Session["name of variable"]=value//value can be anything string ,int or array
and to retrieve the value u hv to type cast the session variable accordingly
eg int a=Convert.ToInt16(Session["some interger varaible"]);
string str=Session["some string var"].ToString();

So the would this be correct, to create the session variables?

Session("LoginId") = LoginId1.Text
Session("Password") = Password1.Text

And then to retrive the variables just say to post them on the next page in new textboxes:

Textbox1.Text = Session("LoginId").ToString
Textbox2.Text = Session("Password").ToString

Cause it's not working, can someone please let me know what I am doing wrong?

Thank you.

Where are you loading and setting the session variables?

You can load them in Page_Load, and set them for example lets say after the user clicks login

Also ensure your web application supports it. I believe it is
EnableSessionState=true

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.