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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:08:41+00:00 2026-05-11T18:08:41+00:00

I have a UserControl which I have added to my web.config <add tagPrefix=BCF src=~/controls/MyMessageBox.ascx

  • 0

I have a UserControl which I have added to my web.config

<add tagPrefix="BCF" src="~/controls/MyMessageBox.ascx" tagName="error"/>

and added to my master page

<BCF:error ID="BCError" runat="server" Visible="false" />

Now I need to be able to reference this control AND its public properties from all child pages that use that masterpage. I did this is my BasePage OnLoad event

public UserControl BCError;
BCError = (UserControl)Master.FindControl("BCError");

Problem is, although I can do this in the .aspx page

BCError.Visible = true;

I cannot reference any of the Controls properties I have put in? Such as ShowError .. If I do

BCError.ShowError = "Error Message";

I just get an error saying

‘System.Web.UI.UserControl’ does not contain a definition for ‘ShowInfo’ and no extension method ‘ShowInfo’

Can you please point me in the right direction!

This is the code for the user control… I can use the properties in the masterpage code behind (And in a page if I put the control directly into it) but cannot use them in the child page code behind?? It doesn’t even show the properties or wrapper methods in the intellisense?

    using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class MyMessageBox : System.Web.UI.UserControl
{
    #region Properties
    public bool ShowCloseButton { get; set; }

    #endregion

    #region Load
    protected void Page_Load(object sender, EventArgs e)
    {
        if (ShowCloseButton)
            CloseButton.Attributes.Add("onclick", "document.getElementById('" + MessageBox.ClientID + "').style.display = 'none'");
    }
    #endregion

    #region Wrapper methods
    public void ShowError(string message)
    {
        Show(MessageType.Error, message);
    }

    public void ShowInfo(string message)
    {
        Show(MessageType.Info, message);
    }

    public void ShowSuccess(string message)
    {
        Show(MessageType.Success, message);
    }

    public void ShowWarning(string message)
    {
        Show(MessageType.Warning, message);
    } 
    #endregion

    #region Show control
    public void Show(MessageType messageType, string message)
    {
        CloseButton.Visible = ShowCloseButton;
        litMessage.Text = message;

        MessageBox.CssClass = messageType.ToString().ToLower();
        this.Visible = true;
    } 
    #endregion

    #region Enum
    public enum MessageType
    {
        Error = 1,
        Info = 2,
        Success = 3,
        Warning = 4
    } 
    #endregion
}
  • 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-11T18:08:41+00:00Added an answer on May 11, 2026 at 6:08 pm

    Ok I think I reproduced roughly what your describing and I deleted my original answer cause it was way off.

    What I found is that when you want a content page to reference a user control being used in a master page and the control is accesible and what not, you will get an error indicating that you need to reference a specific assembly, and then you get errors indicating that no Method exists of type such and such.

    By adding the Register page directive on the child page to the user control resolved this issue. I reproduced this even with the control defined in the web.config or on the page. In both cases I still had to explicitly add a Register on the content page.

    This doesn’t make sense to me but it allowed my code to compile and work. Give it a shot let me know.

    Once you do this you can reference the control like

    this.Master.MessageBox.ShowInfo();
    

    This assumes that you have a public property called MessageBox on the Master Page.

    Edit

    I’ve also found that this works much better if you register the control on both the master and the content page and not use the web.config.

    Edit

    If you don’t want your child page to reference the user control your other option is expose methods on the master page like ShowInfo() which would delegate to the user control.

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

Sidebar

Related Questions

Hi I have a usercontrol which includes some JavaScript, if I add the control
The problem: I have a UserControl (LightBox) which overlays a number of other controls
I have a ContainerPanel to which I added a UserControl. Is there a way
I have written a web usercontrol (ascx). Inside, there is a Panel that I
I have an application in which i have added a usercontrol on the form.
I have a System.Web.UI.UserControl in my application which is to be used to display
I have created a wpf application into which I have added a user control
I have a UserControl which overrides the OnRender-Method as follow: MyUsercontrol.cs: MyUserControl: UserControl {
I have a UserControl which contains a TextBox . When my main window loads
I have a UserControl A which contains a dropdown a placeholder At runtime 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.