title: problem with viewstate of dynamic controls inside a repeater
body: <p>I ran into a problem recently when using a repeater that I was adding dynamic controls into and although I've got a workaround that does functionally exactly what I want it to do, I'd like to know if there is a better way to do it for my understanding. I've been working with ASP.NET for about 6 months now, and everytime I think I've got the page lifecycle/viewstate completely sussed something crops up that I can't answer.</p>
  
  <p>I was creating a form where users could register their interest for an event, and register for multiple people.</p>
  
  <p>The aspx went something like:</p>
  
  <pre><code>&lt;asp:Repeater ...&gt;
      &lt;bunch of formatting and always there controls like firstname/lastname/address&gt;
      &lt;asp:PlaceHolder ...&gt;
          &lt;dynamic controls for workshop selection go here&gt;
      &lt;/asp:PlaceHolder&gt;
  &lt;/asp:Repeater&gt;
  </code></pre>
  
  <p>An event can have workshops that the user can register for, and the availability of the workshops is dependant on the date that they choose to go to the event on. The availability of the workshops is dependent on the date, so they can't choose the workshops until they've selected a date.</p>
  
  <p>Anyway the dynamic controls that I'm adding are basically a bunch of literals and a bunch of radio button groups.</p>
  
  <p>I started off by adding the controls in the ItemDataBound event handler, but when saving my repeater items back to my delegate list the ViewState of the radio buttons was never updated. All the fields that were referenced in the ItemTemplate were handled fine, but not the radio buttons I was adding dynamically.</p>
  
  <p>I tried to use the ItemCreated event instead, adding my buttons there, but that didn't seem to make any difference. In the end I settled on a workaround which was based off of <a href="http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/msg/f742774cac529b2c?pli=1" rel="noreferrer">this</a>. Basically I'm just outputing the HTML input fields in a literal and reading them back from the request.</p>
  
  <p>It all works perfectly now, and I'm happy with the functionality, it just seems really dirty to have to output the radio buttons as HTML inputs directly rather than use a server side control. Does anyone have a clue about why the ViewState wasn't being restored properly?</p>
  
  <p>Just to be clear, the controls were recreated in the same order everytime, with the ID properly set. I'm using dynamic controls all over the place and they're working fine, I just can't get them to work in this case when I'm adding them inside a repeater.</p>
  
  <p>//more clarification</p>
  
  <p>I can't create these controls in Page.Init as the user selects the date which causes a postback and I have to wait for the viewstate of that control to load before I create the dynamic controls.</p>