Referencing Page Controls from the Codebehind's Base Class in ASP.NET 2.0

M

matt

Hi,

I have two very similar pages, whose codebehind I'd like to derive from
the same base class so I can reuse the controller logic.

For (hopeful) clarity I'll try and draw this in ASCII-UML!


PageBase
^ ^
PageA PageB
^ ^
PageA_aspx PageB_aspx

What I find though, is that I can't get access to the control from the
common base type. I guess this is because the controls are created as
fields on the subclass by the code generator. Is there any way to do
this? I'm thinking I may need to use a helper class instead and just
pass it references to all the controls on Page.Init or something...

cheers,
Matt
 
F

Flinky Wisty Pomm

A base class can only access public or internal members of its derived
classes.

If the controls aren't declared on the base page, you won't be able to
access them. It sounds like what you're really describing is a
composite control, if that helps your thinking at all, ie. instead of
passing all your controls to a separate helper class, make your
controls members of a composite control class and use it on both pages.
 

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

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,085
Latest member
cryptooseoagencies

Latest Threads

Top