Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Session Vars

  Asked By: Bastet    Date: Oct 27    Category: Asp.net    Views: 897
  

I have created a session var and I am using it in one of my pages. Sometimes the session var loses its value and nothing displays where I am using it. How am I losing this value?

Here is my code:


Sub Page_Load(Src As Object, E As EventArgs)
Dim ConnectString As String
MyConnect = New SqlConnection
connectString = ConfigurationSettings.AppSettings("ConnectStr")
MyConnect.ConnectionString = ConnectString
Lbl_Biller.text = session("UserCode")
If Not IsPostBack Then
BindGrid()
DropDown()
End If

End Sub

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Troy Kelley     Answered On: Oct 27

You need to convert to the correct type

in C# it's

Lbl_Biller.Text = (string)Session("UserCode") ... ( equiv in VB is CType I think)... but that sometimes fails saying "invalid Cast"

Lbl_Biller.Text = Session("UserCode").ToString() ..... usually works

Lbl_Biller.Text = Convert.ToString(Session("UserCode")) has never failed as far as I can remember

 
Didn't find what you were looking for? Find more on Session Vars Or get search suggestion and latest updates.




Tagged: