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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:53:46+00:00 2026-05-24T01:53:46+00:00

I have three usercontrols: usercontrolA , usercontrolB and usercontrolC which all share the same

  • 0

I have three usercontrols: usercontrolA, usercontrolB and usercontrolC which all share the same codebehind each having:

<%@ Control Language="c#" AutoEventWireup="True" Codebehind="usercontrolA.ascx.cs" Inherits="usercontrolA" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> at the top of the ascx.

In the codebehind file I have a public property called ShowAll.

I know I can set this property when I put the usercontrol on the page e.g.

<uc1:usercontrolB ID="usercontrolB1" runat="server" ShowAll="true" />

However I would like ShowAll to always be set to true on usercontrolB so would rather not have to set it every time it is placed on a page.

I know I can add a script tag to usercontrolB to set ShowAll in Page_Load:

<script runat="server">
    protected void Page_Load(object sender, System.EventArgs e)
    {
        ShowAll = true;
    }
</script>

But want to keep the Page_Load implementation I already have in the codebehind. Is there any other way to set this property automatically for usercontrolB?

Edit: If it’s possible I’d like to be able to set this in the ascx rather than in the code behind, so that someone else later on could add usercontrolD and set ShowAll to true for all instances of usercontrolD without needing to get me to modify and recompile the codebehind.

  • 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-24T01:53:47+00:00Added an answer on May 24, 2026 at 1:53 am

    You have to set this in usercontrol class constructor.

    public ConstructorClassName()
        {
           ShowAll = true;
        }
    

    here is complete example with code…

    public partial class WebUserControl : System.Web.UI.UserControl
    {
      public WebUserControl()
      {
        ShowAll = true;
      }
      private bool _showAll;
      public bool ShowAll
      {
        get { return _showAll; }
        set { _showAll = value; }
      }   
    
      protected void Page_Load(object sender, EventArgs e)
      {
      }
    }
    

    I set the default value to true, but you can also pass the value where you add this user control. e.g.

    <uc1:usercontrolB ID="usercontrolB1" runat="server" ShowAll="false" />
    

    When this is called, it will overwrite the value to false

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

Sidebar

Related Questions

I'm making some controls which all have to share the same look and some
I have three dropdowns for selecting a year inside a user control. On load
I have usercontrols which inherit a base class which looks like this: BasePage.cs: using
I currently have a couple different user controls that provide the same functionality: three
Here's the problem....I have three components...A Page that contains a User Control and a
Say I have a number of usercontrols, each usercontrol inside a tabitem, inside a
I have many usercontrols that i reuse in different projects. They are all in
For each UI control on wpf, there is a 'loaded' event. Suppose I have
I have a UserControl that consists of three TextBoxes. On a form I can
I have three tables: page, attachment, page-attachment I have data like this: page ID

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.