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 6711309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:07:29+00:00 2026-05-26T08:07:29+00:00

Base classes for Page and UserControl: public class MyWebPage : System.Web.UI.Page { } public

  • 0

Base classes for Page and UserControl:

public class MyWebPage : System.Web.UI.Page { }

public class MyUserControl : System.Web.UI.UserControl { }

Helper that either of them might use:

void SetSessionValue<T>(string key, T value) { Session[key] = value; }

How can I achieve something like the following?

public class WebObject // can't inherit from both Page and UserControl { 
   protected void SetSessionValue<T>(string key, T value) { 
      Session[key] = value; 
   }
}  

public class MyWebPage : WebObject { }

public class MyUserControl : WebObject { }

Update: I got excited for a second hoping I could solve it this way, but alas it doesn’t compile.

public class WebObject<T> : T
{
}
public class MyWebPage : WebObject<System.Web.UI.Page>
{
}
  • 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. Editorial Team
    Editorial Team
    2026-05-26T08:07:29+00:00Added an answer on May 26, 2026 at 8:07 am

    You can’t. Not easily anyway. I’d recommend just creating a base class for pages and user controls, and duplicating the common code in both. Since user controls are contained in pages, you can also delegate methods in the base user control class to the base page class simply by casting the Page property to your own type:

    // Code in the MyUserControlBase class
    public int SomeCommonMethod() {
        return ((MyBasePageType)this.Page).SomeCommonMethod();
    }
    

    You can also make your life miserable by creating an interface implemented by both base classes and using DI to intercept method and property accessor calls, which would then be routed to some kind of common surrogate class that actually provides the implementation. I probably wouldn’t go there 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I have a base class for my pages which inherits System.Web.UI.Page and
My base page looks like: namespace ASDF.Mvc.ViewEngines.Razor { public abstract class WebViewPage<TModel> : System.Web.Mvc.WebViewPage<TModel>
Have STI classes: class Page < ActiveRecord::Base belongs_to :user end class FirstTypePage < Page
I've create a custom attribute for my web pages... In the base page class
I have 4 base classes: class A { virtual SomeMethod () { <code> }
I'm trying to extend some base classes in Python: class xlist (list): def len(self):
Does having several levels of base classes slow down a class? A derives B
Currently I'm using a base class for some Customer model classes. As defined as
What cool functionality and methods do you add to your ASP.net BasePage : System.Web.UI.Page
Examples I read of class structure typically begin with a base class and that

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.