Okay, this is a bit abstract, but here goes:
I'm creating a website and I want to have a field, "foo", that I can access from any page on the site. I figured the best way to do this would be to create a subclass of Page called "bar", add the protected field "foo" to it, and then have all my webpages inheret from "bar". Ta-da. Every page now has foo.
But now I add controls to my pages, and I want them to have access to "foo".
Well, now foo can't be protected, so it's public. Fine. But how do the controls know about "foo"? I can access foo by doing something like this in my control:
Foo foo = ((Bar)Page).foo;
This works, but strikes me as a bit ugly. I'd really like to just be able to use foo. I figure, hey, maybe I can do the same trick with my controls that I did for page. I create a new class, "blargh" that inherits from UserControl, and grab foo in there the ugly way. Then I have my controls inherit from blargh. Yay!
Except it doesn't work. When I start up the project it complains about the line trying to access ((Bar)Page).foo, because Page is null. Why? How could Page be null? When I look at the call stack I get no help.
Is there an easy, well understood way to do this? Am I barking up the wrong tree?