Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot get Textboxes in dynamically added usercontrol to maintain state
    text
    copied!<p>I have tried what seems like everything - I've done similiar things many times before, but I'm obviously missing something.</p> <p>I have a UserControl (ucA) - on ucA is a LinkButton that loads a different UserControl (ucB) programatically into a panel on ucA. ucB has TextBoxes, etc. </p> <p>Could someone please help me be sane again? :-)</p> <p>Why isn't my control maintaining it's state? ie: The textboxes are loosing thier value on postback - the control tree shows the name of the control and the Form values show the value (in trace.axd)</p> <p>Here is the code for ucA (basically)</p> <pre><code>public int SlideCount { get { return Convert.ToInt32(ViewState["SlideCount"]); } set { ViewState["SlideCount"] = value; } } protected void LinkButton1_Click(object sender, EventArgs e) { SlideCount += 1; LoadSlideControls(); } protected override void OnInit(EventArgs e) { base.OnInit(e); LoadSlideControls(); } private void LoadSlideControls() { this.pnlAnnouncementHolder.Controls.Clear(); for (int i = 0; i &lt; SlideCount; i++) { this.pnlAnnouncementHolder.Controls.Add( LoadControl("AnnouncementSlide.ascx")); } } </code></pre> <p>Heres a full example of what im trying to do: Thank you Vyrotek for looking at it :-) <a href="http://keithsblogs.com/ControlTest2.zip" rel="nofollow noreferrer">http://keithsblogs.com/ControlTest2.zip</a></p> <p>The problem Vyrotek points out is that the control is added a little to late to the lifecycle on the click event - anyone have any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload