//
// System.Web.UI.WebControls.RadioButton.cs
//
-// Authors:
-// Gaurav Vaish (gvaish@iitk.ac.in)
-// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
+// Author:
+// Dick Porter <dick@ximian.com>
//
-// (C) Gaurav Vaish (2002)
-// (C) 2003 Andreas Nahr
-//
-
+// 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
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-\r
-using System;\r
-using System.Collections;\r
-using System.Collections.Specialized;\r
-using System.Globalization;\r
-using System.Web;\r
-using System.Web.UI;\r
+
+using System.Collections.Specialized;
using System.ComponentModel;
-using System.ComponentModel.Design;\r
-\r
-namespace System.Web.UI.WebControls\r
-{\r
- [Designer ("System.Web.UI.Design.WebControls.CheckBoxDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]\r
- public class RadioButton : CheckBox, IPostBackDataHandler\r
- {\r
- public RadioButton () : base ()\r
- {\r
+using System.Security.Permissions;
+
+namespace System.Web.UI.WebControls {
+
+ // CAS
+ [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+ [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+ // attributes
+ [Designer ("System.Web.UI.Design.WebControls.CheckBoxDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
+#if NET_2_0
+ [SupportsEventValidation]
+#endif
+ public class RadioButton : CheckBox , IPostBackDataHandler
+ {
+ public RadioButton () : base ("radio")
+ {
}
-\r
-#if NET_2_0\r
- [ThemeableAttribute (false)]\r
-#endif\r
- [DefaultValue (""), WebCategory ("Behavior")]
- [WebSysDescription ("The name of the group that this control belongs to.")]\r
- public virtual string GroupName\r
- {\r
- get {\r
- object o = ViewState ["GroupName"];\r
- return (o == null) ? String.Empty : (string) o;\r
- }\r
-\r
- set { ViewState ["GroupName"] = value; }\r
- }\r
-\r
- protected override void OnPreRender (EventArgs e)\r
- {\r
- base.OnPreRender (e);\r
- if (Page != null && Enabled && !Checked)\r
- Page.RegisterRequiresPostBack (this);\r
-\r
- if(GroupName.Length == 0)\r
- GroupName = UniqueID;\r
- }\r
-\r
- internal override void RenderInputTag (HtmlTextWriter writer, string id)\r
- {\r
- writer.AddAttribute (HtmlTextWriterAttribute.Id, id);\r
- writer.AddAttribute (HtmlTextWriterAttribute.Type, "radio");\r
- writer.AddAttribute (HtmlTextWriterAttribute.Name, UniqueGroupNamePrivate);\r
- writer.AddAttribute (HtmlTextWriterAttribute.Value, ValueAttributePrivate);\r
-\r
- if (Checked)\r
- writer.AddAttribute (HtmlTextWriterAttribute.Checked, "checked");
- \r
- if (!Enabled)
- writer.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled");
-\r
- if (AutoPostBack){\r
- writer.AddAttribute (HtmlTextWriterAttribute.Onclick,\r
- Page.GetPostBackClientEvent (this, ""));\r
- writer.AddAttribute ("language", "javascript");\r
- }\r
-\r
- if (AccessKey.Length > 0)\r
- writer.AddAttribute (HtmlTextWriterAttribute.Accesskey, AccessKey);\r
-\r
- if (TabIndex != 0)
- writer.AddAttribute (HtmlTextWriterAttribute.Tabindex,\r
- TabIndex.ToString (NumberFormatInfo.InvariantInfo));\r
-\r
- writer.RenderBeginTag (System.Web.UI.HtmlTextWriterTag.Input);\r
- writer.RenderEndTag ();\r
- }\r
- private string UniqueGroupNamePrivate
+ [DefaultValue ("")]
+#if NET_2_0
+ [Themeable (false)]
+#endif
+ [WebSysDescription ("")]
+ [WebCategory ("Behavior")]
+ public virtual string GroupName
{
get {
- string retVal;
- string uid = UniqueID;
- int unique = uid.LastIndexOf (':');
- if (unique == -1) {
- retVal = GroupName;
- } else {
- retVal = uid.Substring (0, unique + 1) + GroupName;
+ return (ViewState.GetString ("GroupName",
+ String.Empty));
+ }
+ set {
+ ViewState["GroupName"] = value;
+ }
+ }
+
+ internal override string NameAttribute
+ {
+ get {
+ string unique = UniqueID;
+ string gn = GroupName;
+ if (gn.Length == 0)
+ return unique;
+ int colon = -1;
+ if (unique != null) {
+#if NET_2_0
+ colon = unique.LastIndexOf (IdSeparator);
+#else
+ colon = unique.IndexOf (IdSeparator);
+#endif
}
+
+ if (colon == -1)
+ return gn;
+
+ return unique.Substring (0, colon + 1) + gn;
+ }
+ }
- return retVal;
+ internal string ValueAttribute {
+ get {
+ string val = (string)ViewState ["Value"];
+ if (val != null)
+ return val;
+
+#if NET_2_0
+ string id = ID;
+ if (!String.IsNullOrEmpty (id))
+ return id;
+ else
+#endif
+ return UniqueID;
}
+ set {
+ ViewState["Value"] = value;
+ }
+ }
+
+ internal override void InternalAddAttributesToRender (HtmlTextWriter w)
+ {
+#if NET_2_0
+ Page page = Page;
+ if (page != null)
+ page.ClientScript.RegisterForEventValidation (NameAttribute, ValueAttribute);
+#endif
+ base.InternalAddAttributesToRender (w);
+ w.AddAttribute (HtmlTextWriterAttribute.Value, ValueAttribute);
}
- private string ValueAttributePrivate\r
- {\r
- get {\r
- string retVal = Attributes ["value"];\r
- if (retVal != null)\r
- return retVal;\r
-\r
- if (ID != null)\r
- return ID;\r
-\r
- return UniqueID;\r
- }\r
- }\r
-\r
-\r
-#if NET_2_0\r
- bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)\r
- {\r
- return LoadPostData (postDataKey, postCollection);\r
- }\r
- \r
- protected override bool LoadPostData (string postDataKey, NameValueCollection postCollection)\r
-#else\r
- bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)\r
-#endif\r
- {\r
- bool _checked = Checked;\r
- if (postCollection [UniqueGroupNamePrivate] == ValueAttributePrivate){\r
- if (_checked)\r
- return false;\r
- Checked = true;\r
- return true;\r
- }\r
-\r
- if (_checked)\r
- Checked = false;\r
- return true;\r
- }\r
-\r
-#if NET_2_0\r
- void IPostBackDataHandler.RaisePostDataChangedEvent ()\r
- {\r
- RaisePostDataChangedEvent ();\r
- }\r
- \r
- protected override void RaisePostDataChangedEvent ()\r
- {\r
- OnCheckedChanged (EventArgs.Empty);\r
- }\r
-#else\r
- void IPostBackDataHandler.RaisePostDataChangedEvent ()\r
- {\r
- OnCheckedChanged (EventArgs.Empty);\r
- }\r
-#endif\r
- }\r
-}\r
+#if NET_2_0
+ protected internal
+#else
+ protected
+#endif
+ override void OnPreRender (EventArgs e)
+ {
+ base.OnPreRender (e);
+ }
+
+#if NET_2_0
+ protected override
+#endif
+ bool LoadPostData (string postDataKey, NameValueCollection postCollection)
+ {
+ string value = postCollection [NameAttribute];
+ bool checkedOnClient = value == ValueAttribute;
+#if NET_2_0
+ ValidateEvent (NameAttribute, value);
+#endif
+ if (Checked == checkedOnClient)
+ return false;
+
+ Checked = checkedOnClient;
+ return checkedOnClient;
+ }
+
+#if NET_2_0
+ protected override void RaisePostDataChangedEvent ()
+ {
+ if (CausesValidation)
+ Page.Validate (ValidationGroup);
+ OnCheckedChanged (EventArgs.Empty);
+ }
+#endif
+
+ bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
+ {
+ return LoadPostData (postDataKey, postCollection);
+ }
+ }
+}