title: Custom RadioButtonList loses value on PostBack
body: <p>I created a custom RadioButtonList which renders as an unordered list based on a similar <a href="http://sim.plified.com/2008/04/18/checkboxlist-as-and-unordered-list-css-stylable/" rel="nofollow">code example for a custom CheckBoxList</a>.</p>
  
  <p>But for some reason my selected item isn't saved when performing a postback.
  The only method I overrided is the Render-method:</p>
  
  <pre><code>[ToolboxData( "&lt;{0}:ULRadioButtonList runat=server&gt;&lt;/{0}:ULRadioButtonList&gt;" )]
  public class ULRadioButtonList : RadioButtonList {
      protected override void Render( HtmlTextWriter writer ) {
          Controls.Clear();
  
          string input = "&lt;input id={0}{1}{0} name={0}{2}{0} type={0}radio{0} value={0}{3}{0}{4} /&gt;";
          string label = "&lt;label for={0}{1}{0}&gt;{2}&lt;/label&gt;";
          string list = "&lt;ul&gt;";
  
          if ( !String.IsNullOrEmpty( CssClass ) ) {
              list = "&lt;ul class=\"" + CssClass + "\"&gt;";
          }
  
          writer.WriteLine( list );
  
          for ( int index = 0; index &lt; Items.Count; index++ ) {
              writer.Indent++;
              writer.Indent++;
  
              writer.WriteLine( "&lt;li&gt;" );
  
              writer.Indent++;
  
              StringBuilder sbInput = new StringBuilder();
              StringBuilder sbLabel = new StringBuilder();
  
              sbInput.AppendFormat(
                  input,
                  "\"",
                  base.ClientID + "_" + index.ToString(),
                  base.UniqueID,
                  base.Items[index].Value,
                  (base.Items[index].Selected ? " checked=\"\"" : "")
              );
  
              sbLabel.AppendFormat(
                  label,
                  "\"",
                  base.ClientID + "_" + index.ToString(),
                  base.Items[index].Text
              );
  
              writer.WriteLine( sbInput.ToString() );
              writer.WriteLine( sbLabel.ToString() );
  
              writer.Indent = 1;
  
              writer.WriteLine( "&lt;/li&gt;" );
  
              writer.WriteLine();
  
              writer.Indent = 1;
              writer.Indent = 1;
          }
  
          writer.WriteLine( "&lt;/ul&gt;" );
      }
  }
  </code></pre>
  
  <p>Did I forget something? If I use a regular ASP.NET RadioButtonList my selected item is saved after the postback so there is nothing else which is overriding my value; it has something to do with the custom control.</p>