<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Web Forms</title><link>http://forums.asp.net/18.aspx</link><description>All about building ASP.NET Pages - server controls, events, validation, etc.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Dynamically loaded user controls.</title><link>http://forums.asp.net/thread/2491021.aspx</link><pubDate>Tue, 15 Jul 2008 15:40:35 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2491021</guid><dc:creator>daniel.saidi</dc:creator><author>daniel.saidi</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2491021.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=18&amp;PostID=2491021</wfw:commentRss><description>&lt;p&gt;The previous post was rather old, but the issue with dynamically loaded user controls still remain.&lt;br /&gt;&lt;br /&gt;All dynamically loaded controls are unloaded from the page when a postback occurs. They will thus not remain on the page if you press a button or perform a PostBack in any way. This is quite annoying, since you manually have to reload any dynamically loaded controls to the page after the postback. You must also make sure to reload them at the right time and with the correct ID...otherwise they will not work properly. For instance, events may not fire, nested controls may crasch etc.&lt;/p&gt;&lt;p&gt;This can become quite a problem for large, complex web applications where dynamically loaded controls are essential to keep down byte size and avoid a lot of unnecessary functionality. 

A very simple and handy solution to this issue is described in this blog:&lt;/p&gt;&lt;p&gt;

&lt;a href="http://daniel-saidi.blogspot.com/2008/07/aspnet-dynamically-loaded-usercontrol.html" target="_blank"&gt;http://daniel-saidi.blogspot.com/2008/07/aspnet-dynamically-loaded-usercontrol.html&lt;/a&gt;

&lt;/p&gt;&lt;p&gt;It features a slimmed, downloadable class which, hopefully, will take care of this issue for you.&lt;/p&gt;</description></item><item><title>Re: Dynamically loaded user controls.</title><link>http://forums.asp.net/thread/432429.aspx</link><pubDate>Fri, 02 Jan 2004 22:37:00 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:432429</guid><dc:creator>PLBlum</dc:creator><author>PLBlum</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/432429.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=18&amp;PostID=432429</wfw:commentRss><description>Every control on the page has a unique ID called the ClientID. (That's an actual property on each control.) A user control is a &amp;quot;naming container&amp;quot;. That means each control it contains also contains the ID of the User control. For example, &amp;quot;TextBox1&amp;quot; in UserControl with the ID &amp;quot;UserControl1&amp;quot; will have the clientID:
&lt;br /&gt;
UserControl1_TextBox1.
&lt;br /&gt;

&lt;br /&gt;
Post back retrieves the values from each field by the ClientID. For example, to get the above TextBox's value from the form, use Request.Forms[&amp;quot;UserControl1_TextBox1&amp;quot;].
&lt;br /&gt;
Now what happens when you replace one UserControl with another that has the same ClientID? The second gets the data of the first.
&lt;br /&gt;

&lt;br /&gt;
Recommendations:
&lt;br /&gt;
1. Always assign a unique ID to the UserControl in its ID property.
&lt;br /&gt;
2. You should always recreate the controls of the page you sent to the browser on postback before rearranging them. That allows the original controls to load their data and run their event handlers. It also allows the ViewState to properly distribute its contents without getting a ViewState corrupted error.
&lt;br /&gt;

&lt;br /&gt;
So on Post_Back, I recommend calling LoadControl to get the original UserControl. Then before loading the second, set the first's Visible property to false to remove it.</description></item><item><title>Dynamically loaded user controls.</title><link>http://forums.asp.net/thread/432354.aspx</link><pubDate>Fri, 02 Jan 2004 20:56:15 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:432354</guid><dc:creator>scorchandburn</dc:creator><author>scorchandburn</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/432354.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=18&amp;PostID=432354</wfw:commentRss><description>I have a series of user controls that I am loading dynamically based on selection of a drop down list.  The problem I am having is when the second control is dynamically loaded because the user made a different selection from the drop down the first dynamically loaded controls values remain in the second controls fields.
&lt;br /&gt;

&lt;br /&gt;
I am loading the controls in the overridden LoadViewState(object savedState) method.  This allows me to retain viewstate of the dynamically loaded control on postback.
&lt;br /&gt;

&lt;br /&gt;
Any ideas as to why this would be happening.
&lt;br /&gt;

&lt;br /&gt;
Thanks!</description></item></channel></rss>