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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:25:30+00:00 2026-06-14T08:25:30+00:00

I am trying to access a DropDownList within a div after I add them

  • 0

I am trying to access a DropDownList within a div after I add them from the code-behind.
If I add DropDownList to my .aspx page like this:

<div id="FiltersDiv" runat="server">
                <asp:DropDownList ID="DropDownListMenu" runat="server" 
                      DataTextField="name" DataValueField="id"
                    AutoPostBack="true" 
                      onselectedindexchanged="DropDownListMenu_SelectedIndexChanged" >
                </asp:DropDownList>

I can get access in any event

protected void AddButton_Click(object sender, EventArgs e)
 {
   var dl = addProductLocationFiltersDiv.Controls.OfType<DropDownList>();
 }

but not if I add from code

var ddl = new DropDownList();
 ddl.DataSource = flist;
 ddl.DataTextField = "name";
 ddl.DataValueField = "id";
 ddl.DataBind();
 FiltersDiv.Controls.Add(ddl);

I need to add several DropDownList’s and I do not now how many will be. So, I need to looping thru.
Did I miss some attribute or how I need to do it?

  • 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-14T08:25:31+00:00Added an answer on June 14, 2026 at 8:25 am

    When you add a control via code, you access it through the variable name.

    If you need access to several of these, consider putting then in a List<DropDownList> (or List<Control> if you have different types of controls).

    If you need to share these across methods in your code behind, use a field instead of a local variable.

    Note, that due to how the ASP.NET page lifecycle works, you will probably need to recreate these on every postback, otherwise you will not be able to access them. The best location to recreate such controls dynamically is in the OnInit handler.

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

Sidebar

Related Questions

i am trying access an asp label within an asp repeater from my code
Trying to access a Servlet from a button on HTML page //Html Page FORM
Im trying to access information from two different arrays within my viewModel with two
I'm trying to extend the DropDownList control to simply add one extra property. Code
I am trying to access my local resources file in my code-behind. I did
i cannot get current content page html. when i trying access from script in
Trying to access file attributes from an input field after a file is selected.
Im trying to access the org.testng.reporters.XMLReporter from my Java code. I am writing code
Trying to access a property from the parent page on my user control. Here's
I am trying to access all the data from database listOfFolder table folder and

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.