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

  • Home
  • SEARCH
  • 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 9182039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:27:56+00:00 2026-06-17T18:27:56+00:00

I have several custom user controls (100+) that all have a common formatting involved

  • 0

I have several custom user controls (100+) that all have a common formatting involved which basically requires us to wrap the user control in a panel control on the destination page. For simplicity, I wanted to create a base control that handles this, as almost all of the base features are the same for each of the custom controls.

What I have done to accomplish this is to create a base class, inside that base class I create a private panel control, and then I override the Render to generate the panel pre/post tags around the base.Render.

Now this works great as all of the user controls that we care about that are inheriting this and the few formatting items that we have exposed to the inherited controls work as expected (Width, CssClass, etc).

What I would really like is to expose all of the panel control items to the inherited control through the base class, but without having to right a property/method to expose each element.

Any ideas on what the best approach is for this? I just don’t want to implement each and every panel property/method manually. We use the design time attributes as well (number one is CssClass and Width) but we have been entending the user of design time attributes…

What we have works, just looking for a easier/better solution.

using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public class BaseUserControl : System.Web.UI.UserControl
{
    private Panel _panel;
    private bool _isPanelLoaded;

    public Panel Panel
    {
        get
        {
            if (_panel == null)
            {
                _panel = new Panel();
                _isPanelLoaded = true;
            }
            return _panel;
        }
    }

    public BaseUserControl()
    {

    }

    protected override void Render(HtmlTextWriter writer)
    {
        if (_isPanelLoaded)
        {
            Panel.RenderBeginTag(writer);
            base.Render(writer);
            Panel.RenderEndTag(writer);
        }
        else
        {
            base.Render(writer);
        }
    }

    public Unit Width
    {
        get
        {
            if (Panel.Width.IsEmpty)
            {
                return 0;
            }
            return Panel.Width;
        }
        set
        {
            Panel.Width = value;
        }
    }

    public string CssClass
    {
        get
        {
            return Panel.CssClass;
        }
        set
        {
            Panel.CssClass = value;
        }
    }
}
  • 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-06-17T18:27:57+00:00Added an answer on June 17, 2026 at 6:27 pm

    In order to expose all the properties, you have to inherit from the Panel control. Since you have a panel property, you could set the properties on that property. To define them in markup is the challenge… with most simple objects, if you give the property an attribute of <PersistenceMode(PersistenceMode.Attribute)>, you would be able to access the properties in the sytnax of Panel-CssClass, but I don’t know if that will work for you, since Panel is a control. Good to try.

    You’re essentially talking about writing properties once that wrap the attributes you want, so it may be best just to do that, if the former solution doesn’t work.

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

Sidebar

Related Questions

I have custom event that has several different subscribers who will all use the
I have a custom view with several NSTextField controls for which I want to
I have several UITextView subviews, all using the same custom input interface (basically a
I have several Entity Framework Code First DbContext objects that use a custom Initializer.
I'm using a custom JLayeredPane. I have several Shapes which needed to be drawn
I have a custom UITableViewCell which contains several UIButtons. Each button's frame position is
I've got a Silverlight 4 custom control that basically is several Canvas elements wrapped
I have a program with several custom controls. One of these custom controls is
I've set up a UITableView with several custom UITableViewCell's that have some UITextField's and
I have created a custom user control that is meant to extend the functionality

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.