-/* System.Web.UI.HtmlControls\r
-* Authors\r
-* Leen Toelen (toelen@hotmail.com)\r
-*/\r
-\r
-using System;\r
-using System.Collections.Specialized;\r
-using System.ComponentModel;\r
-using System.Globalization;\r
-using System.Web;\r
-using System.Web.UI;\r
-\r
-namespace System.Web.UI.HtmlControls{\r
- \r
- [DefaultEvent("ServerChange")]\r
- public class HtmlInputRadioButton : HtmlInputControl, IPostBackDataHandler{\r
- \r
- private static readonly object EventServerChange;\r
- \r
- public HtmlInputRadioButton(): base("radio"){}\r
- \r
- protected override void OnPreRender(EventArgs e){\r
- if (Page != null && !Disabled){\r
- Page.RegisterRequiresPostBack(this);\r
- }\r
- if (Events[EventServerChange] != null && !Disabled){\r
- ViewState.SetItemDirty("checked", false);\r
- }\r
- }\r
- \r
- protected virtual void OnServerChange(EventArgs e){\r
- EventHandler handler = (EventHandler) Events[EventServerChange];\r
- if (handler != null){\r
- handler.Invoke(this, e);\r
- }\r
- }\r
- \r
- protected override void RenderAttributes(HtmlTextWriter writer){\r
- writer.WriteAttribute("value", Value);\r
- Attributes.Remove("value");\r
- base.RenderAttributes(writer);\r
- }\r
- \r
- bool IPostBackDataHandler.LoadPostData (string postDataKey,\r
- NameValueCollection postCollection)\r
- {\r
- string postValue = postCollection [postDataKey];\r
- bool myBool = false;\r
- if (postValue != null && postValue.Equals (Value)) {\r
- if (!Checked) {\r
- Checked = true;\r
- myBool = true;\r
- }\r
- } else {\r
- if (Checked) {\r
- Checked = false;\r
- myBool = false;\r
- }\r
- }\r
- return myBool;\r
- }\r
- \r
- void IPostBackDataHandler.RaisePostDataChangedEvent ()\r
- {\r
- OnServerChange (EventArgs.Empty);\r
- }\r
- \r
- [WebCategory("Action")]\r
- [WebSysDescription("Fires when the checked state of the control changes.")]\r
- public event EventHandler ServerChange{\r
- add{\r
- Events.AddHandler(EventServerChange, value);\r
- }\r
- remove{\r
- Events.RemoveHandler(EventServerChange, value);\r
- }\r
- }\r
- \r
- [DefaultValue("")]\r
- [WebCategory("Misc")]\r
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]\r
- public bool Checked{\r
- get{\r
- string attr = Attributes["checked"];\r
- if (attr != null){\r
- return attr.Equals("checked");\r
- }\r
- return false;\r
- }\r
- set{\r
- if (value != true){\r
- Attributes["checked"] = null;\r
- }\r
- Attributes["checked"] = "checked";\r
- }\r
- }\r
- public override string Name\r
- {\r
- get {\r
- string attr = Attributes ["name"]; // Gotta use "name" to group radio buttons\r
- return (attr == null) ? String.Empty : attr;\r
- }\r
- set { Attributes ["name"] = value; }\r
- }\r
- \r
- protected override string RenderedName{\r
- get{\r
- string attr = base.RenderedName;\r
- string id = UniqueID;\r
- int indexOfX = id.LastIndexOf('X');\r
- if (indexOfX != 0 && indexOfX >= 0){\r
- attr = String.Concat(attr, id.Substring(0,indexOfX+1));\r
- }\r
- return attr;\r
- }\r
- }\r
-\r
- public override string Value\r
- {\r
- get {\r
- string v = Attributes ["value"];\r
- if (v != null && v != "")\r
- return v;\r
- v = ID;\r
- Attributes ["value"] = v;\r
- return v;\r
- }\r
-\r
- set { Attributes ["value"] = value; }\r
- }\r
- \r
- } // class HtmlInputRadioButton\r
-} // namespace System.Web.UI.HtmlControls\r
-\r
+//
+// System.Web.UI.HtmlControls.HtmlInputRadioButton.cs
+//
+// Author:
+// Sebastien Pouliot <sebastien@ximian.com>
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System.ComponentModel;
+using System.Collections.Specialized;
+using System.Security.Permissions;
+
+namespace System.Web.UI.HtmlControls {
+
+ // CAS
+ [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+ [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+ // attributes
+ [DefaultEvent ("ServerChange")]
+#if NET_2_0
+ [SupportsEventValidation]
+#endif
+ public class HtmlInputRadioButton : HtmlInputControl, IPostBackDataHandler
+ {
+ static readonly object serverChangeEvent = new object ();
+
+ public HtmlInputRadioButton ()
+ : base ("radio")
+ {
+ }
+
+ [DefaultValue ("")]
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+ [WebSysDescription("")]
+ [WebCategory("Misc")]
+ public bool Checked {
+ get { return (Attributes ["checked"] == "checked"); }
+ set {
+ if (value)
+ Attributes ["checked"] = "checked";
+ else
+ Attributes.Remove ("checked");
+ }
+ }
+
+ public override string Name {
+ get {
+ string s = Attributes ["name"];
+ return (s == null) ? String.Empty : s;
+ }
+ set {
+ if (value == null)
+ Attributes.Remove ("name");
+ else
+ Attributes ["name"] = value;
+ }
+ }
+
+ public override string Value {
+ get {
+ string s = Attributes ["value"];
+ if (s == null || s.Length == 0) {
+ s = ID;
+ if ((s != null) && (s.Length == 0))
+ s = null;
+ }
+ return s;
+ }
+ set {
+ if (value == null)
+ Attributes.Remove ("value");
+ else
+ Attributes ["value"] = value;
+ }
+ }
+
+#if NET_2_0
+ protected internal
+#else
+ protected
+#endif
+ override void OnPreRender (EventArgs e)
+ {
+ base.OnPreRender (e);
+
+ if (Page != null && !Disabled) {
+ Page.RegisterRequiresPostBack (this);
+#if NET_2_0
+ Page.RegisterEnabledControl (this);
+#endif
+ }
+ }
+
+ protected virtual void OnServerChange (EventArgs e)
+ {
+ EventHandler serverChange = (EventHandler) Events [serverChangeEvent];
+ if (serverChange != null)
+ serverChange (this, e);
+ }
+
+ protected override void RenderAttributes (HtmlTextWriter writer)
+ {
+#if NET_2_0
+ if (Page != null)
+ Page.ClientScript.RegisterForEventValidation (this.UniqueID, Value);
+#endif
+ writer.WriteAttribute ("value", Value, true);
+ Attributes.Remove ("value");
+ base.RenderAttributes (writer);
+ }
+#if NET_2_0
+ protected virtual
+#endif
+ bool LoadPostData (string postDataKey, NameValueCollection postCollection)
+ {
+ bool checkedOnClient = postCollection [Name] == Value;
+ if (Checked == checkedOnClient)
+ return false;
+
+#if NET_2_0
+ ValidateEvent (UniqueID, Value);
+#endif
+ Checked = checkedOnClient;
+ return checkedOnClient;
+ }
+
+#if NET_2_0
+ protected virtual
+#endif
+ void RaisePostDataChangedEvent ()
+ {
+ OnServerChange (EventArgs.Empty);
+ }
+
+ bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
+ {
+ return LoadPostData (postDataKey, postCollection);
+ }
+
+ void IPostBackDataHandler.RaisePostDataChangedEvent ()
+ {
+ RaisePostDataChangedEvent ();
+ }
+
+
+ [WebSysDescription("")]
+ [WebCategory("Action")]
+ public event EventHandler ServerChange {
+ add { Events.AddHandler (serverChangeEvent, value); }
+ remove { Events.RemoveHandler (serverChangeEvent, value); }
+ }
+ }
+}