X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Web%2FSystem.Web.UI.HtmlControls%2FHtmlInputRadioButton.cs;h=15589da533f65ea9b6927d1734bd74876395f3f8;hb=a5e40870bd3bb18e1681afed6c71e7edfdb80534;hp=d8ba51d79f756e0c2584c3d754536dc01b7f1fc7;hpb=26c28da39170a4b8b791931d6e09cbff23d03e6c;p=mono.git diff --git a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputRadioButton.cs b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputRadioButton.cs old mode 100755 new mode 100644 index d8ba51d79f7..15589da533f --- a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputRadioButton.cs +++ b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputRadioButton.cs @@ -1,134 +1,173 @@ -/* System.Web.UI.HtmlControls -* Authors -* Leen Toelen (toelen@hotmail.com) -*/ - -using System; -using System.Collections.Specialized; -using System.ComponentModel; -using System.Globalization; -using System.Web; -using System.Web.UI; - -namespace System.Web.UI.HtmlControls{ - - [DefaultEvent("ServerChange")] - public class HtmlInputRadioButton : HtmlInputControl, IPostBackDataHandler{ - - private static readonly object EventServerChange; - - public HtmlInputRadioButton(): base("radio"){} - - protected override void OnPreRender(EventArgs e){ - if (Page != null && !Disabled){ - Page.RegisterRequiresPostBack(this); - } - if (Events[EventServerChange] != null && !Disabled){ - ViewState.SetItemDirty("checked", false); - } - } - - protected virtual void OnServerChange(EventArgs e){ - EventHandler handler = (EventHandler) Events[EventServerChange]; - if (handler != null){ - handler.Invoke(this, e); - } - } - - protected override void RenderAttributes(HtmlTextWriter writer){ - writer.WriteAttribute("value", Value); - Attributes.Remove("value"); - base.RenderAttributes(writer); - } - - bool IPostBackDataHandler.LoadPostData (string postDataKey, - NameValueCollection postCollection) - { - string postValue = postCollection [postDataKey]; - bool myBool = false; - if (postValue != null && postValue.Equals (Value)) { - if (!Checked) { - Checked = true; - myBool = true; - } - } else { - if (Checked) { - Checked = false; - myBool = false; - } - } - return myBool; - } - - void IPostBackDataHandler.RaisePostDataChangedEvent () - { - OnServerChange (EventArgs.Empty); - } - - [WebCategory("Action")] - [WebSysDescription("Fires when the checked state of the control changes.")] - public event EventHandler ServerChange{ - add{ - Events.AddHandler(EventServerChange, value); - } - remove{ - Events.RemoveHandler(EventServerChange, value); - } - } - - [DefaultValue("")] - [WebCategory("Misc")] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool Checked{ - get{ - string attr = Attributes["checked"]; - if (attr != null){ - return attr.Equals("checked"); - } - return false; - } - set{ - if (value != true){ - Attributes["checked"] = null; - } - Attributes["checked"] = "checked"; - } - } - public override string Name - { - get { - string attr = Attributes ["name"]; // Gotta use "name" to group radio buttons - return (attr == null) ? String.Empty : attr; - } - set { Attributes ["name"] = value; } - } - - protected override string RenderedName{ - get{ - string attr = base.RenderedName; - string id = UniqueID; - int indexOfX = id.LastIndexOf('X'); - if (indexOfX != 0 && indexOfX >= 0){ - attr = String.Concat(attr, id.Substring(0,indexOfX+1)); - } - return attr; - } - } - - public override string Value - { - get { - string v = Attributes ["value"]; - if (v != null && v != "") - return v; - v = ID; - Attributes ["value"] = v; - return v; - } - - set { Attributes ["value"] = value; } - } - - } // class HtmlInputRadioButton -} // namespace System.Web.UI.HtmlControls - +// +// System.Web.UI.HtmlControls.HtmlInputRadioButton.cs +// +// Author: +// Sebastien Pouliot +// +// 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); } + } + } +}