ViewState property can not be accessed in derived class ???

Discussion in 'ASP .Net' started by Chris Peeters, Aug 10, 2007.

  1. Hi,

    Using inheritance, doesn't 'protected' mean that derived classes can
    access that data if specified as protected in the base class ?

    Aparently not: ViewState property is declared as protected in the
    Control class. ListBox inherits (indirectly) from Control but the
    ViewState property can not be accessed ???

    It generates following compiler error :
    "Cannot access protected member
    'System.Web.UI.Control.ViewState' via a qualifier of type
    'System.Web.UI.WebControls.ListBox'; the qualifier must be of
    type 'PageCounter' (or derived from it)"

    How come ?

    Thank you
    Chris

    *** Sent via Developersdex http://www.developersdex.com ***
    Chris Peeters, Aug 10, 2007
    #1
    1. Advertising

  2. On 10 Aug, 11:30, Chris Peeters <> wrote:
    > Hi,
    >
    > Using inheritance, doesn't 'protected' mean that derived classes can
    > access that data if specified as protected in the base class ?
    >
    > Aparently not: ViewState property is declared as protected in the
    > Control class. ListBox inherits (indirectly) from Control but the
    > ViewState property can not be accessed ???
    >
    > It generates following compiler error :
    > "Cannot access protected member
    > 'System.Web.UI.Control.ViewState' via a qualifier of type
    > 'System.Web.UI.WebControls.ListBox'; the qualifier must be of
    > type 'PageCounter' (or derived from it)"
    >
    > How come ?
    >
    > Thank you
    > Chris
    >
    > *** Sent via Developersdexhttp://www.developersdex.com***


    Hi Chris,

    Are you writing a derived class?

    Perhaps you could post some code to clarify the problem you're having?


    Brett.
    Brett Wiltshire, Aug 10, 2007
    #2
    1. Advertising

  3. Hello,

    I just try to type in Page_Load()

    lstColors.ViewState["test"] = 0;

    with lstColors defined as a normal asp-ListBox.

    ViewState is the inherited property.

    but I realised what i am doing wrong:

    I try to access the listbox-protected property from a different class,
    page-class , which is not allowed of course !
    Page class can only access its own inherited ViewState-property.

    thanks anyway
    Chris

    *** Sent via Developersdex http://www.developersdex.com ***
    Chris Peeters, Aug 10, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. crash.test.dummy
    Replies:
    0
    Views:
    328
    crash.test.dummy
    Mar 15, 2006
  2. Shelly Adhikari
    Replies:
    3
    Views:
    354
    red floyd
    Sep 10, 2003
  3. Bangalore
    Replies:
    3
    Views:
    402
    werasm
    Jun 23, 2006
  4. Replies:
    1
    Views:
    384
    myork
    May 23, 2007
  5. Replies:
    1
    Views:
    372
    Victor Bazarov
    May 23, 2007
Loading...

Share This Page