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

C

Chris Peeters

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
 
B

Brett Wiltshire

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.
 
C

Chris Peeters

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top