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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:49:55+00:00 2026-05-11T14:49:55+00:00

Let me start with pointing out, this is not an easy question to answer.

  • 0

Let me start with pointing out, this is not an easy question to answer. At least it’s dead near impossible to find the answer.

In an UpdatePanel I dynamically add some controls to a panel control of mine.

List<Showing> showings = cBLL.GetShowings(tenant.Id);          int j = 1;         foreach(Showing showing in showings)         {             UserControl uc = (UserControl)Page.LoadControl('Controls/BookShowing.ascx');             uc.ID = 'showing_' + j;             uc.Visible = true;             ((BookShowing)uc).SetShowing(showing);             pnl_showings.Controls.Add(uc);             j++;         } 

This all takes place in a button event fired from a control asychrone.

Below these fields I add in the code shown above I have a button. The button is also placed in the updatepanel. This button is called: btn_editShowings

Now when I come to the btn_editShowings_Click event handler, my dynamic added controls does not exist anymore. I have also tried catching them in the OnInit but they dont exist there either.

How the F… is it ever possible to obtains data from the dynamic added controls??? Is there anyway, and I don’t care how lousy it performs or anything, to solve this?

UPDATE:

I have now tried to do the following which should work as Init fires before LoadViewState from what I have read.

I add some controls dynamic in a Button event

    protected void Button2_Click(object sender, EventArgs e)     {              for (int i = j; i < showno + 4; i++)                 {                     UserControl uc = (UserControl)Page.LoadControl('Controls/BookShowing.ascx');                     uc.ID = 'showing_' + i;                     uc.Attributes.Add('runat', 'Server');                     uc.EnableViewState = true;                     uc.Visible = true;                     pnl_showings.Controls.Add(uc);                 }           UpdatePanel1.Update();     } 

And I have done the same thing in my init function: protected override void OnInit(EventArgs e) { base.OnInit(e);

        if (Session['ShowingsCount'] != null)         {             int noOfUCs = (int)Session['ShowingsCount'];             for (int i = 1; i < noOfUCs; i++)             {                 UserControl uc = (UserControl)Page.LoadControl('Controls/BookShowing.ascx');                 uc.ID = 'showing_' + i;                 uc.Attributes.Add('runat', 'Server');                 uc.EnableViewState = true;                 uc.Visible = true;                 pnl_showings.Controls.Add(uc);             }             UpdatePanel1.Update();         }     } 

But when I try this:

FindControl('showing_1').Visible = false; 

I get a null reference exception.

Best Regards The Real Napster, troubled once again.

  • 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. 2026-05-11T14:49:55+00:00Added an answer on May 11, 2026 at 2:49 pm
    1. When you add the controls the first time, keep track of the number of controls you need to recreate in the viewstate.
    2. On every post-back after that make sure you add that number of controls back onto the page with the same IDs in the LoadViewState method.

    The key is that you always have to add dynamically created controls to the page every post-back and you have to do it before the viewstate loads in order for the controls to get their form-posted values loaded back into them.

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

Sidebar

Related Questions

OK. The title of this qiestion is not easy to decode, but let me
Let me start by pointing out that while I've been using Java SE for
Let me start off by clarifying that(before you guys dismiss me), this is not
Let me start by saying that I do not advocate this approach, but I
Let me start by explaining this is my first Android app. So I don't
Let me start off with a bit of background. This morning one of our
Let me start by saying I'm a huge fan of the elegance of this
Let me start off by saying that I am not an expert in C.
I have this code: for i in 1 .. 10 do let (tree, interval)
Let me start of by saying that as I don't know how to search

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.