Reputation: 3746
How can I access the values stored in a session object with a class in asp.net?
Upvotes: 0
Views: 5204
Reputation: 335
Have your class constructor take in a HttpContext.Current
object parameter. From that object, access the session property.
Upvotes: 0
Reputation: 46077
You should be able to use HttpContext for this:
string sessionValue = HttpContext.Current.Session["SessionKey"] as string;
Just make sure your class imports the System.Web namespace, and this should work fine.
Upvotes: 3
Reputation: 15609
Protected Sub EnterInfoButton_OnClick(ByVal sender As Object, ByVal args As EventArgs)
Session("FirstName") = Server.HtmlEncode(FirstNameTextBox.Text)
Session("LastName") = Server.HtmlEncode(LastNameTextBox.Text)
Session("Address") = Server.HtmlEncode(AddressTextBox.Text)
Session("City") = Server.HtmlEncode(CityTextBox.Text)
Session("StateOrProvince") = Server.HtmlEncode(StateOrProvinceTextBox.Text)
Session("ZipCode") = Server.HtmlEncode(ZipCodeTextBox.Text)
Session("Country") = Server.HtmlEncode(CountryTextBox.Text)
EnterUserInfoPanel.Visible = False
UserInfoPanel.Visible = True
SetLabels()
End Sub
Upvotes: 0