PDA

View Full Version : asp.net session variable problem


schristy
04-23-2008, 05:57 PM
I have a student who is trying to solve an ASP.net VB problem and we're missing something simple. Can someone look at this?

The first screen asks for a student ID number, if it exists in the members dbase, it creates a session variable called "currentuser" and lets them in to the main area. If not, it creates a session variable called "usernotfound" and sends them to a page where they can become a member.

On the new member page we want it to automatically fill in the student number field (a text field) using the value stored in the "usernotfound" session variable. I thought this would be easy by setting Text='<%=session("usernotfound") %>' in the form but of course it's never that easy is it? :rolleyes:

What did I miss? This SHOULD be so simple.

BTW, I know this probably isn't the best use of sessin variables and that it could be passed as an URL parameter but the directions for this particular chapter require it since they just learned session variables.

chump2877
04-23-2008, 06:10 PM
In C#, sessions work as follows:

string myString = "string";
Session['myString'] = myString;
string newString = (string)Session['myString'];

In this code:

Text='<%=session("usernotfound") %>'

I'm guessing you need to cast the session variable to the right type:

Text='<%=(string)Session["usernotfound"] %>'

..there might be a small difference in syntax with VB versus C#, but the idea is the same..