Session State variables within UserControls [modified]
-
Scenario: - I have session state variables being saved and loaded from an ASP.NET page. - I have session state variables being set from within a UserControl that exists on that same page. Problem: - When I set a session state variable within the codebehind page of the UserControl and the page performs a postback I am unable to access the session state variable that was set within the UserControl during the OnInit method of the ASP.NET page that the control is on? - I am checking this by enumerating the session state variable collection for the page at both the OnInit and OnLoad methods of the page and the controls session state variables are not available at either. However, after the page has loaded I look at the trace information and see that the user controls session state variables are there (but not in the collection during the pages OnLoad event....) Question: - In regards to the accessability of the UserControls session state variables on the page: Are the session state variables loaded into the pages session state collection during the loading of the control itself (which is why I cant access them during the OnInit phase of the Page itself?) - Shouldn't Session state variables be accessable to the page and all children controls of that page for that user? I'm going to try to move some of the code that uses the session variable to a later rendering phase of which it's accessable however there is some things I'm doing that have to be done in the OnInit, OnPreRender, etc. page load phases... Thanks for any insight you can provide =P -- modified at 6:34 Friday 14th July, 2006
-
Scenario: - I have session state variables being saved and loaded from an ASP.NET page. - I have session state variables being set from within a UserControl that exists on that same page. Problem: - When I set a session state variable within the codebehind page of the UserControl and the page performs a postback I am unable to access the session state variable that was set within the UserControl during the OnInit method of the ASP.NET page that the control is on? - I am checking this by enumerating the session state variable collection for the page at both the OnInit and OnLoad methods of the page and the controls session state variables are not available at either. However, after the page has loaded I look at the trace information and see that the user controls session state variables are there (but not in the collection during the pages OnLoad event....) Question: - In regards to the accessability of the UserControls session state variables on the page: Are the session state variables loaded into the pages session state collection during the loading of the control itself (which is why I cant access them during the OnInit phase of the Page itself?) - Shouldn't Session state variables be accessable to the page and all children controls of that page for that user? I'm going to try to move some of the code that uses the session variable to a later rendering phase of which it's accessable however there is some things I'm doing that have to be done in the OnInit, OnPreRender, etc. page load phases... Thanks for any insight you can provide =P -- modified at 6:34 Friday 14th July, 2006
The user control doesn't have any separate session variables, there is only one Session object for the request. If there is no session variable, it simply hasn't been created yet. You have to wait until the user control has been created. --- b { font-weight: normal; }
-
Scenario: - I have session state variables being saved and loaded from an ASP.NET page. - I have session state variables being set from within a UserControl that exists on that same page. Problem: - When I set a session state variable within the codebehind page of the UserControl and the page performs a postback I am unable to access the session state variable that was set within the UserControl during the OnInit method of the ASP.NET page that the control is on? - I am checking this by enumerating the session state variable collection for the page at both the OnInit and OnLoad methods of the page and the controls session state variables are not available at either. However, after the page has loaded I look at the trace information and see that the user controls session state variables are there (but not in the collection during the pages OnLoad event....) Question: - In regards to the accessability of the UserControls session state variables on the page: Are the session state variables loaded into the pages session state collection during the loading of the control itself (which is why I cant access them during the OnInit phase of the Page itself?) - Shouldn't Session state variables be accessable to the page and all children controls of that page for that user? I'm going to try to move some of the code that uses the session variable to a later rendering phase of which it's accessable however there is some things I'm doing that have to be done in the OnInit, OnPreRender, etc. page load phases... Thanks for any insight you can provide =P -- modified at 6:34 Friday 14th July, 2006
You know what to do yet you chose to ask the question? Anyway, you'll never get lost doing that. Just access the HttpCookie in the Pageload event. I suppose during init, variables havent been created yet. Live in fragments no longer. Only connect.