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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:44:50+00:00 2026-06-04T09:44:50+00:00

There are two different UserControls which share some common Properties. What I’d like to

  • 0

There are two different UserControls which share some common Properties.
What I’d like to do is to switch between these two based on an external flag.

UserControl u1, u2;

if(flag)
{
    u1 = u1 as ControlType1;
    u2 = u2 as ControlType1;
}
else
{
    u1 = u1 as ControlType2;
    u2 = u2 as ControlType2;
}

SomeMethod(u1.SelectedItemName, u2.SelectedItemName);

Since UserControl doesn’t have a property called “SelectedItemName”, the code would not throw error.

What I’ve currently done is, I’ve added an extension method on UserControl which gets the “SelectedItemName” using reflection, and I get the value by calling u1.SelectedItemName() instead of u1.SelectedItemName;

My question is what is an easy way to fix this without using extension/ maybe the right way. Note that I don’t want to repeat the SomeMethod(a,b) inside the if statement.

  • 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-04T09:44:52+00:00Added an answer on June 4, 2026 at 9:44 am

    My suggestion would be to make both of these UserControl classes implement a shared interface or derive from a shared base class. You could then develop against the base class or interface without worrying about the flags/switches at all.

    IYourUserControl u1, u2;
    
    SomeMethod(u1, u2);
    

    This would work provided SomeMethod was defined as:

    void SomeMethod(IYourUserControl one, IYourUserControl two) { // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In javascript, is there any different between these two: // call MyFunction normal way
Lets say there are two pages with two different html elements which have the
As I see it there are two different types of logging: User-focused logs, like
Is there any difference between these two LINQ statements: var query = from a
I've found that there are two different properties of the order in Magento API
I'm creating an application in which there's two different types of users. Should I
I have a model Post which belongs_to one Section . There are two different
If there are two slots in two different threads and these slots are connected
There are two different ideas about the element which plays role of default command
In struts I notice there are two different ways to access variables. I am

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.