1stein

asp.net RadioButtonList bug

Jun 2nd, 2011
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1.     public class MyRadioButtonList : RadioButtonList
  2.     {
  3.         private const string ScriptTemplate = "window.document.getElementById('{0}_{1}').checked = true;";
  4.  
  5.         protected override void OnPreRender(EventArgs e)
  6.         {
  7.             base.OnPreRender(e);
  8.  
  9.             if (!Page.IsPostBack)
  10.             {
  11.                 for (int i = 0; i < Items.Count; i++)
  12.                 {
  13.                     if (Items[i].Selected)
  14.                     {
  15.                         Items[i].Selected = false;
  16.                         Page.ClientScript.RegisterStartupScript(typeof(RadioButtonList), string.Format("0}_DefaultValue", this.ClientID), string.Format(ScriptTemplate, this.ClientID, i), true);
  17.                         break;
  18.                     }
  19.                 }
  20.             }
  21.         }
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment