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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:34:14+00:00 2026-06-14T22:34:14+00:00

I want to fill an updatepanel with new dynamic controls in response to a

  • 0

I want to fill an updatepanel with new dynamic controls in response to a button click.

However, I also want to be able to access the values of these dynamic controls in response to an event in one of the controls.

Specifically, I want the button to bring up two dropdownmenus. One of the menus (or both if need be) is in another update panel. I want the first menu in the update panel to change its data in response to a value getting selected in the other menu.

I think my problem is that when I cause a postback with one dropdownmenu I lose the other dropdownmenu because I created it in the button_click handler.

I know I should create dynamic controls in the Page_Init method (or so ive heard) but I only want the controls to show up if the button is clicked. There are other buttons on the page which need to create a different set of dynamic controls.

Thanks.

  • 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-14T22:34:15+00:00Added an answer on June 14, 2026 at 10:34 pm

    There are a lot of ways you can handle this, and which approach to take really depends on your project’s requirements and your available resources.

    The smoothest way to do it that would generally provide the best user experience would be to use a Javascript technique to hide and show controls as the page required them. JQuery is the library I would recommend for this. On the most basic level, you simply wire the control’s activation (such as a button_click event) and hide or show a div containing the dynamic content as necessary, like so:

    $("#control").show();
    // and
    $("#control").hide();
    

    Alternatively, you can do this in C# by using the Visible property on many of the normal web controls for ASP.NET. The usual code-behind approach would look something like this:

    private void btnControl_Click(object sender, EventArgs e)
    {
        var dynamicControl1 = FindControl("dynamicControl1");
        dynamicControl.Visible = false; // or true, as the case may be
    }
    

    This particular approach is mostly attached to code-behinds, though, which I would encourage you to avoid if possible. They are practically impossible to test and will make projects a pain to work in. You can use a similar approach in the MVC3 framework, of course, it will just be a little different how you send and receive the control you are setting to not be visible. The other benefit this has that is kind of nice is that if something is set to not be visible, it tends not to even be displayed in the HTML generated by the templating engine (YMMV depending on the engine, but I know this is true in Razor). So someone viewing the source of your webpage won’t be able to see inactive controls, which may or may not be something that appeals to you.

    EDIT: I see the problem is less to do with how to display these things, and more with how to create and read them back given on-the-fly input.

    I’m sure there’s a way to do this with Javascript (which would more than probably be the cleanest and best way to do this), but I’m not good enough with JS to know the answer to that one. The way you would handle this in ASP.NET is make the div you’re going to add controls to server-side (by using runat='server', then add what you need there. Again, the trivial code-behind approach would be something like:

    private void btnControl_Click(object sender, EventArgs e)
    {
        foreach(var checkBoxChecked in chkBoxes.Where(x => x.Checked))
        {
            div.Controls.Add(new WebControl()) // or whatever the heck else it is you need.
        }
    }
    

    This presumes that you have an IEnumerable<CheckBox> to iterate over, of course. You may also want an IList<WebControl> to keep track of all the junk you’re adding. You will also need to make sure the CSS is applied properly to the div for the controls you’re adding. And again, code-behinds are pretty awful and I use the example only because it’d be easy to spin up in a project to test for yourself.

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

Sidebar

Related Questions

I want to fill an array in javascript that takes all the values out
I want to fill a combobox on Form1 , when the OK button on
I want to fill these containers pretty quickly with some data for testing. What
I want to fill an ArrayList with these characters +,-,*,^ etc. How can I
Using VB.Net I want to fill a combobox with table values by using 3
I have two fields I want to fill with the exactly same values; users
I want to fill a ListView without an array of all the same things.
I want to fill jqGrid from a stored procedure, there was 1 good example
I want to fill all cells with the same control. What I have now
I simply want to fill-up cells in my spreadsheet from a VBA function. By

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.