Cant get the value from a textbox control into session object

  • Thread starter Thread starter Chumley the Walrus
  • Start date Start date
C

Chumley the Walrus

I have a textbox control that represents a username in a password
scheme, and I'm trying to turn the ID of the textbox control (the id =
lgname ) into a session object. Doing lgname.text = Session("lgname")
is not working, as I don't see the entered username on the next page
when I simply do a hard code such as Response.write
(session("lgname"))
 
Hi Chumley,

Session("lgname") = lgname.Text would place the Text property into a
session varialble. Having the statement reversed is trying to read the
session variable into the TextBox.
 
Chumley.

To get the value from the textbox on your page and put it into a session
variable do this:

Session.Add("UserName",TextBox.Text.Trim());

or you could do this:

Session["UserName"] = TextBox.Text.Trim();

To get the Session variable back out to populate your text box, do this:

TextBox.Text = (string)Session["UserName"];

you need to cast "(string)" the session Username object back into a string.

hth,
TPS.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top