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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 78k
  • Answers 78k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The CGContextSaveGState documentation explicitly states what is saved in the… May 11, 2026 at 3:58 pm
  • added an answer If you go with tasklist, it might actually be faster… May 11, 2026 at 3:58 pm
  • added an answer %* will always expand to all original parameters, sadly. But… May 11, 2026 at 3:57 pm

Related Questions

In VS .NET, when you are selecting a folder for a project, a dialog
I have several web pages on several different sites that I want to mirror
Let me start with a specific example of what I'm trying to do. I
Let me start off with a bit of background. This morning one of our

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.