I want to add session variables (right now i have query string) in my application.
I want to add session variables that can capture the user's userid and email from a table
How do i do that (code? to write?), i triedSession["username"]=Textbox1.text, on the 1st .aspx page
anD wrote
If Session["username"]!= nullthen
lblname.text =Session["username"].tostringEndIf
but it doesnt work
Do i have to do changes in the web.config file? if so what changes ? also do i have to write a new /seperate table in the database?
This is the first time i am using session variables ...i dont understand whats exactly i am supposed to do?
By default you can use the Session In-Proc.
You simply need to add this:
Session["KeyName"] = Textbox1.Text;
On another page, simply use this:
if (Session["KeyName"] != null) && (Session["KeyName"].ToString() != "")
{
// Your code goes here
}
It should work without configuring anything in the web application!
Regards
Session by default is stored in memory, so you don't have to do anything.
this syntax is wrong
If Session["username"]!= nullthenlblname.text =Session["username"].tostringEndIf
the != and null are for C#, in Visual Basic you would do the following
If Not Session("username") Is Nothingthenlblname.Text =Session("username").ToString()
EndIf
edit:corrected the ["..."] to ("...") (VB syntax for collections)
i get this error :property access must assign to property or use its value
You are trying to retreive some property, you are not assigning its value to a variable or using it in an expression, nor are you setting the value of the property. Please post the line of code which has this error.
Session["username"]=Textbox1.text
Session("username")= Textbox1.text
In fact, I've always used Session.Item("username")= Textbox1.text. I didn't realise you could skip the Item
SSpost:
How do i do that (code? to write?), i tried
Session["username"]=Textbox1.text, on the 1st .aspx page
anD wrote
IfSession["username"]!= nullthen
lblname.text =Session["username"].tostringEndIf
just see above code
which code behind language you are using?
in c#
Session["username"] = TextBox1.Text;
if(Session["username"]!= null)
TextBox1.Text = Session["username"].ToString();
in vb
Session("username") = TextBox1.Text
If Not Session("username") Is Nothing Then
TextBox1.Text = Session("username").ToString()
End If
0 comments:
Post a Comment