1 /* System.Web.UI.HtmlControls
3 * Leen Toelen (toelen@hotmail.com)
7 using System
.Collections
.Specialized
;
8 using System
.ComponentModel
;
9 using System
.Globalization
;
13 namespace System
.Web
.UI
.HtmlControls
{
15 [DefaultEvent("ServerChange")]
16 public class HtmlInputRadioButton
: HtmlInputControl
, IPostBackDataHandler
{
18 private static readonly object EventServerChange
= new object ();
20 public HtmlInputRadioButton(): base("radio"){}
22 protected override void OnPreRender(EventArgs e
){
23 if (Page
!= null && !Disabled
){
24 Page
.RegisterRequiresPostBack(this);
26 if (Events
[EventServerChange
] != null && !Disabled
){
27 ViewState
.SetItemDirty("checked", false);
31 protected virtual void OnServerChange(EventArgs e
){
32 EventHandler handler
= (EventHandler
) Events
[EventServerChange
];
38 protected override void RenderAttributes(HtmlTextWriter writer
){
39 writer
.WriteAttribute("value", Value
);
40 Attributes
.Remove("value");
41 base.RenderAttributes(writer
);
44 bool IPostBackDataHandler
.LoadPostData (string postDataKey
,
45 NameValueCollection postCollection
)
47 string postValue
= postCollection
[Name
];
49 if (postValue
!= null && postValue
.Equals (Value
)) {
63 void IPostBackDataHandler
.RaisePostDataChangedEvent ()
65 OnServerChange (EventArgs
.Empty
);
68 [WebCategory("Action")]
69 [WebSysDescription("Fires when the checked state of the control changes.")]
70 public event EventHandler ServerChange
{
72 Events
.AddHandler(EventServerChange
, value);
75 Events
.RemoveHandler(EventServerChange
, value);
81 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
84 string attr
= Attributes
["checked"];
86 return attr
.Equals("checked");
92 Attributes
["checked"] = "checked";
94 Attributes
.Remove ("checked");
97 public override string Name
100 string attr
= Attributes
["name"]; // Gotta use "name" to group radio buttons
101 return (attr
== null) ? String
.Empty
: attr
;
103 set { Attributes ["name"] = value; }
106 internal override string RenderedName
{
108 string attr
= base.RenderedName
;
109 string id
= UniqueID
;
110 int indexOfX
= id
.LastIndexOf('X');
111 if (indexOfX
!= 0 && indexOfX
>= 0){
112 attr
= String
.Concat(attr
, id
.Substring(0,indexOfX
+1));
118 public override string Value
121 string v
= Attributes
["value"];
122 if (v
!= null && v
!= "")
125 Attributes
["value"] = v
;
129 set { Attributes ["value"] = value; }
132 } // class HtmlInputRadioButton
133 } // namespace System.Web.UI.HtmlControls