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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:47:19+00:00 2026-06-05T22:47:19+00:00

I have a situation, don’t know if my approach is right or not please

  • 0

I have a situation, don’t know if my approach is right or not please guide me through this.
Suppose I have a Panel control containing numerous controls in it,
During runtime I performed an iteration over each control in that panel by using
Panel1.Controls property,
Now in those controls they could be anything TextBox, Button, DropDown etc.
Now I want to find during runtime, which Controls is of which type and after that find if any specific property is contained in that control or not & if that property exists there than set the value of that property.
I think I would have to do some thing using Reflection here but don’t know from where to start.

sample code:

 foreach (Control cntrl in Panel1.Controls)
        { 
            //find type of the control
            // find any specific property's existence in that control
            // if property exists than set value of that property
        }

Any other more relevant approach is welcomed too, for performing this task in runtime.

Sorry I forgot to mention
I don’t want to use is keyword here because controls are of may types, and I want to create a global function which can be used for any panel with out knowing the types of controls present in that panel.

Thankx in advance.

  • 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-05T22:47:22+00:00Added an answer on June 5, 2026 at 10:47 pm

    By using reflection you can achieve this.

    Get the metadata for the property, and then set it. This will allow you to check for the existence of the property, and verify that it can be set:

    foreach (Control cntrl in Panel1.Controls)
    { 
       PropertyInfo prop = cntrl.GetType().GetProperty("Name", BindingFlags.Public |            BindingFlags.Instance);
       if(null != prop && prop.CanWrite)
       {
           prop.SetValue(cntrl, "MyName", null);
       }
    }
    

    Or try this if you do not want to use reflection

    foreach (Control cntrl in Panel1.Controls)
                { 
                    if(cntrl is TextBox)
                    {
                      TextBox txt = (TextBox)ctrl;
                      txt.Text = "Your value here";
                      // your textbox code here
                    }
                    else if(cntrl is DropDown)
                    {
                      // your DropDown code here
                    }
                    if(cntrl is Button)
                    {
                      // your Button code here
                    }
                }
    

    Note: is keyword Checks if an object is compatible with a given type. For example, the following code can determine if an object is an instance of the MyObject type, or a type that derives from MyObject:

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

Sidebar

Related Questions

I don't know what it's doing when we have this situation: Foo::Bar It looks
I don't know if you have run into a similar situation but here's a
I have very simple situation and really don't have a clue why this isn't
I have this situation where I have a SqlDatasource control and the select query
I have a situation I don't know how it's supposed to be solved. According
I have situation where table is created dynamically,i don't know the table name it
Don't ask me how but I'm in a situation where I have DCPs published
i have situation like this: class IData { virtual void get() = 0; virtual
I have situation like this: user submits form with action='/pay' in '/pay' I have
I have situation where I generate stylesheets based on information in the database. This

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.