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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:13:59+00:00 2026-06-11T13:13:59+00:00

I want to write a custom control involving a DropDownList and a TextBox .

  • 0

I want to write a custom control involving a DropDownList and a TextBox.
Actually, I want to dynamically render DropDownList and TextBox.
For example: when a user clicks a Checkbox, the Textbox will change to a DropdownList. On the other hand, when a user deselects the Checkbox, the Dropdownlist will change to a Textbox.

I know this can be done using two controls, which sets the visibility for both control. But can I do it on a custom control?

  • 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-11T13:14:00+00:00Added an answer on June 11, 2026 at 1:14 pm

    If you still want to go with that approach, here is your code.

    In Design File:-

     <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True"
     oncheckedchanged="CheckBox1_CheckedChanged" />
    
     <div id ="control" runat="server">
    
     </div>
    

    In Code Behind File:-

    protected void Page_Load(object sender, EventArgs e)
    {
      if (!Page.IsPostBack)
       {
         TextBox txt = new TextBox();
         txt.ID = "txt";
         control.Controls.Add(txt);
       }
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
       if (CheckBox1.Checked)
        {
           for (int ix = this.Controls.Count - 1; ix >= 0; ix--)
               if (this.Controls[ix] is TextBox) this.Controls[ix].Dispose();
    
           DropDownList ddl = new DropDownList();
           ddl.ID = "ddl";
    
          control.Controls.Add(ddl);
        }
        else
        {
          for (int ix = this.Controls.Count - 1; ix >= 0; ix--)
              if (this.Controls[ix] is DropDownList) this.Controls[ix].Dispose();
    
           TextBox txt = new TextBox();
           txt.ID = "txt";
    
           control.Controls.Add(txt);
        }
    }
    

    Hope this is what you were looking for.

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

Sidebar

Related Questions

I am attempting to write a custom control. I want to allow its user
I want to write a custom validator which doesn't do anything before the user
I want to write a custom control that's used like this: <HorizontalTick>Some string</HorizontalTick> It
I want to write a custom control (a text editor) for Windows Forms, which
If I want to write a custom command for a button control in WPF,
I want to write a custom control and want it to have different Padding
I am trying to write my own custom TextBox control in Silverlight 5. I
I have a large data set and I want to write a custom merge
I want write a simple query which will fetch data from a table (which
I want to write <a href=product.php?id=5> as product/5.I am not talking about user to

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.