passing values

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I pass a variable from one webpage to another in C# ?
I have created a UserLogin page which wants to pass the value of UserName to
another page called UserPage.

Help appreciated. Thanks.
 
How do I pass a variable from one webpage to another in C# ?
I have created a UserLogin page which wants to pass the value of
UserName to
another page called UserPage.
The easy way would be to use the Session object, which stores data for a
single user session. You could store the login user like this:

Session["UserName"] = "Andrew";

And you can retrieve it (in UserPage) like this:

string sUserName = Convert.ToString( Session["UserName"] );

Both lines may throw an exception if sessions are not enabled, or if the
variable wasn't set.

Greetings,
Wessel
 
If it's only something small then you could use the Session to store it. I
say if it's only something small because if you use the Session too much then
your application scalability will quickly degrade.

Brian Delahunty
Ireland

http://briandela.com/blog
 
It worked. Thanks.

Wessel Troost said:
How do I pass a variable from one webpage to another in C# ?
I have created a UserLogin page which wants to pass the value of
UserName to
another page called UserPage.
The easy way would be to use the Session object, which stores data for a
single user session. You could store the login user like this:

Session["UserName"] = "Andrew";

And you can retrieve it (in UserPage) like this:

string sUserName = Convert.ToString( Session["UserName"] );

Both lines may throw an exception if sessions are not enabled, or if the
variable wasn't set.

Greetings,
Wessel
 
Back
Top