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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:50:00+00:00 2026-05-15T04:50:00+00:00

In my code behind (c#) I dynamically created some RadioButtonLists with more RadioButtons in

  • 0

In my code behind (c#) I dynamically created some RadioButtonLists with more RadioButtons in each of them. I put all controls to a specific Panel.
What I need to know is how to access those controls later as they are not created in .aspx file (with drag and drop from toolbox)?

I tried this:

    foreach (Control child in panel.Controls)
    {
        Response.Write("test1");
        if (child.GetType().ToString().Equals("System.Web.UI.WebControls.RadioButtonList"))
        {
            RadioButtonList r = (RadioButtonList)child;
            Response.Write("test2");
        }   
    }

“test1” and “test2” dont show up in my page. That means something is wrong with this logic.
Any suggestions what could I do?

  • 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-05-15T04:50:01+00:00Added an answer on May 15, 2026 at 4:50 am

    You must recreate your controls after each postback.

    ASP.NET is stateless, that is, when you postback a page to the server, your dynamically created controls won’t be part of the page anymore.

    Last week I had to overcome this situation once more.

    What did I do?
    I saved the data that I used to create the controls inside Session object. On PageLoad method I passed that same data to recreate the dynamic controls.

    What I suggest is:
    Write a method to create the dynamic controls.

    On PageLoad method check to see if it’s a postback…

    if(Page.IsPostBack)
    {
       // Recreate your controls here.
    }
    

    A really important thing: assign unique IDs to your dynamically created controls so that ASP.NET can recreate the controls binding their existing event handlers, restoring their ViewState, etc.

    myControl.ID = "myId";
    

    I had a hard time to learn how this thing works. Once you learn you have power in your hands. Dynamically created controls open up a new world of possibilities.

    As Frank mentioned: you can use the “is” keyword this way to facilitate your life…

    if(child is RadioButtonList)
    

    Note:
    it’s worth to mention the ASP.NET Page Life Cycle Overview page on MSDN for further reference.

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

Sidebar

Related Questions

I have a table that is dynamically created in some c# code-behind when a
We need to dynamically create (i.e. during runtime, via code-behind) UserControls and position them
I'm dynamically generating radio buttons in my code behind and assigning javascript to them
I created a TabPanel on my aspx file. In my code behind, I dynamically
I have multiple asp:button that I created dynamically with jQuery. For each of them,
The following code block allows the user creates textbox controls dynamically. However, on each
I need to create a WPF grid dynamically from code behind. This is going
I'm creating a table in an asp.net code behind dynamically, and I want to
If buttons are dynamically added in wpf from code behind how can you add
I need to change ASPxGridView SettingsLoadingPanel dynamically (from code behind if is possible). For

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.