Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 154337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:57:40+00:00 2026-05-11T09:57:40+00:00

Okay, this is a bit abstract, but here goes: I’m creating a website and

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:57:41+00:00Added an answer on May 11, 2026 at 9:57 am

    Another easy way to get started with this, before you decide which objects will need access and which won’t, is to simply make a public static class to hold this and other global objects. Something like:

    public static class Globals {     public static Foo foo = new Foo(); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay this one may be a bit out from left field, but I'm going
Okay, if I have a html document that looks a bit like this: <div
I have actually seen this question quite a bit here, but none of them
Okay so the title might sound a bit confusing, but here's what I want
Okay this is a bit of a noobish question, but I ran across this
Okay so this query should be easy but I'm having a bit of difficult.
Okay, I have been researching on how to do this, but say I am
Okay, this problem is a bit odd. I have an application built in VS2010
Okay this is a real headscratcher. I have an application which calls a web
Okay I have this RewriteRule which is supposed to redirect any request for the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.