Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Denotes a 'field' where a 'class' was expected

I have a class by the name of "Section" that provides an abstraction over the sections of my ASP.NET web site. The class is compiled into a DLL. I have tested the Section code on pages before and it's all fine. But I am having a problem on one of the pages - the only difference is I am trying to use an instance of section as a global variable.

<script language="C#" runat="server">
    public const int MAX_ARTICLES = 20;

    public static Section thisSection;

    public void Page_Load(Object sender, EventArgs E)
    {
        thisSection = new Section();
        if (thisSection.Load(Convert.ToInt32(Request.Cookies["section"].Value)))
        {


When I try to run the page, I get this error:
Compiler Error Message: CS0118: 'ASP.Default_aspx.thisSection' denotes a 'field' where a 'class' was expected

Silly thing. It works alright when thisSection is declared inside Page_Load(), but when its not I get the error. I'd like thisSection to be avaliable to the whole page though, not just Page_Load(). How do I go about doing this?

Nerdo
Monday, May 17, 2004

There's no reason it should be static - in fact it'd be best if it were non-static.

Duncan Smart
Monday, May 17, 2004

It had originally been public. Then I tried private, protected, and a whole bunch of others, but I'm still having the same problem. Ignore the static :)

Nerdo
Monday, May 17, 2004

Just a though - does your Section class have a default method? Can you post your Section class?

CF
Monday, May 17, 2004

Nerdo - try:

<%@ Import Namespace="{namespace that contains Section class}" %>

Duncan Smart
Tuesday, May 18, 2004

*  Recent Topics

*  Fog Creek Home