using System; using System.Web.UI; using System.Web.UI.WebControls; using System.Globalization; namespace WebBlocks { public class RepeaterRadioButton : RadioButton, IPostBackDataHandler { public RepeaterRadioButton() : base() { } private string Value { get { return (Attributes["value"] == null ? UniqueID : UniqueID + "_" + Attributes["value"]); } } protected override void Render(HtmlTextWriter output) { output.AddAttribute(HtmlTextWriterAttribute.Id, ClientID); output.AddAttribute(HtmlTextWriterAttribute.Type, "radio"); output.AddAttribute(HtmlTextWriterAttribute.Name, GroupName); output.AddAttribute(HtmlTextWriterAttribute.Value, Value); if (Checked) output.AddAttribute(HtmlTextWriterAttribute.Checked, "checked"); if (!Enabled) output.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled"); string onClick = Attributes["onclick"]; if (AutoPostBack) { if (onClick != null) onClick = String.Empty; onClick += Page.ClientScript.GetPostBackEventReference(this, String.Empty); output.AddAttribute(HtmlTextWriterAttribute.Onclick, onClick); output.AddAttribute("language", "javascript"); } else { if (onClick != null) output.AddAttribute(HtmlTextWriterAttribute.Onclick, onClick); } if (AccessKey.Length > 0) output.AddAttribute(HtmlTextWriterAttribute.Accesskey, AccessKey); if (TabIndex != 0) output.AddAttribute(HtmlTextWriterAttribute.Tabindex, TabIndex.ToString(NumberFormatInfo.InvariantInfo)); output.RenderBeginTag(HtmlTextWriterTag.Input); output.RenderEndTag(); } void IPostBackDataHandler.RaisePostDataChangedEvent() { OnCheckedChanged(EventArgs.Empty); } bool IPostBackDataHandler.LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection) { bool result = false; string value = postCollection[GroupName]; if((value != null) && (value == Value)) { if(!Checked) { Checked = true; result = true; } } else { if(Checked) Checked = false; } return result; } } }