• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

ASP.NET Commander Page

I am in the process of building a commander page for my ASP.NET application.  

The commander page is a class that inherits "System.Web.UI.Page"

Then, on webforms within my application, rather than inheriting "System.Web.UI.Page" on the forms, I inherit my commander page.

This works great, up until I try to access Session variables from my commander class.

I've tried several variations, and I keep getting the following error:

"Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive"

Keep in mind, that Session State is ENABLED, and works fine from other locations.  I think this has to do with an order in which the code is being executed but not quite sure.

Any help would be greatly appreciated.

Thanks
0
mmarksbury
Asked:
mmarksbury
  • 3
  • 2
1 Solution
 
raterusCommented:
I do this all the time, and I've never ran into a problem with the session.  Can you post the source of this page?
0
 
mmarksburyAuthor Commented:
using System;
using System.Data;
using System.Configuration;

namespace MyApp.BLL
{
      public abstract class AdminPage : System.Web.UI.Page
      {
            private int      _UserId;
            
            public AdminPage()
            {
                                                _UserId = Convert.ToInt32(this.Session["UserId"]);
                  System.Web.UI.WebControls.Literal PL = new System.Web.UI.WebControls.Literal();
                  PL.Text = _UserId.ToString();
                  this.Controls.Add(PL);
            }
      }
}
0
 
raterusCommented:
You shouldn't be defining your own constructor in this page, rather you should use the normal events of the asp.net page lifecycle to do things.  For example, the code you have looks like it would be better placed in page_init.

--Michael
0
 
mmarksburyAuthor Commented:
an example ?
0
 
mmarksburyAuthor Commented:
Nevermind, I got it.  Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now