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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:27:33+00:00 2026-05-14T23:27:33+00:00

I have a class UserControlBase that inherits System.Web.UI.UserControl and my user controls inherit UserControlBase

  • 0

I have a class UserControlBase that inherits System.Web.UI.UserControl and my user controls inherit UserControlBase class. UserControlBase has some common functions that are used in all user controls.

I want to put error display function to UserControlBase as well so that I may not have to declare and manage it in all user controls. Error will be displayed in some label in usercontrol. Issue is how to access label which is in usercontrol in UserControlBase in function ? I don’t want to pass label as argument.

  • 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-14T23:27:34+00:00Added an answer on May 14, 2026 at 11:27 pm

    In your UserControl Base, expose the text value of the label only:

    public abstract class UserControlBase : System.Web.UI.UserControl
    {
        private Label ErrorLabel { get; set; }
        protected string ErrorMessage
        {
            get { return ErrorLabel.Text; }
            set { ErrorLabel.Text = value; }
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            ErrorLabel = new Label();
            Controls.Add(ErrorLabel);
        }
        //... Other functions
    }
    

    In your user controls that inherit this:

    public partial class WebUserControl1 : UserControlBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
    
            }
            catch (Exception)
            {
                ErrorMessage = "Error";   //Or whatever
    
            }
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a class that is simply THIS Class UserControlBase Inherits UserControl End
I have abstract UserControlBase class inheriting from System.Web.UI.UserControl. It only class, without markup, because
I got a web user control where I have controls that needs to be
I have class User that contains protected constructor and class Account that has access
I have class A that has some primitive attributes and also member of type
I have class ParentClass that observes an NSNotification. ParentClass handles the notification. ChildClass inherits
I have class B that has class A, this is simplified version of class
I have class instantiated in a web service that, in a static member, holds
I have class which has a method that needs to return three DataTables. I
I have class, that has a NSString. @interface AudioManager : NSObject { AudioData *data_;

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.