Merge pull request #2394 from Mailaender/patch-1
[mono.git] / mcs / class / System.Web / System.Web.UI.HtmlControls / HtmlInputRadioButton.cs
index 2912384b2c2ecb31e962a49592e1e7046423e762..bcccf968bcc535cd3944341863b0c7771fbef3e6 100644 (file)
@@ -4,7 +4,7 @@
 // Author:
 //     Sebastien Pouliot  <sebastien@ximian.com>
 //
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005-2010 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
@@ -30,27 +30,23 @@ using System.ComponentModel;
 using System.Collections.Specialized;
 using System.Security.Permissions;
 
-namespace System.Web.UI.HtmlControls {
-
+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 {
-
-               private static readonly object serverChangeEvent = new object ();
-
+       public class HtmlInputRadioButton : HtmlInputControl, IPostBackDataHandler 
+       {
+               static readonly object serverChangeEvent = new object ();
 
                public HtmlInputRadioButton ()
                        : base ("radio")
                {
                }
 
-
                [DefaultValue ("")]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                [WebSysDescription("")]
@@ -96,18 +92,14 @@ namespace System.Web.UI.HtmlControls {
                        }
                }
 
-
-#if NET_2_0
-               protected internal
-#else
-               protected
-#endif         
-               override void OnPreRender (EventArgs e)
+               protected internal override void OnPreRender (EventArgs e)
                {
                        base.OnPreRender (e);
 
-                       if (Page != null) {
-                               Page.RegisterRequiresPostBack (this);
+                       Page page = Page;
+                       if (page != null && !Disabled) {
+                               page.RegisterRequiresPostBack (this);
+                               page.RegisterEnabledControl (this);
                        }
                }
 
@@ -120,48 +112,38 @@ namespace System.Web.UI.HtmlControls {
 
                protected override void RenderAttributes (HtmlTextWriter writer)
                {
-                       writer.WriteAttribute ("value", Value);
+                       Page page = Page;
+                       if (page != null)
+                               page.ClientScript.RegisterForEventValidation (this.UniqueID, Value);
+                       writer.WriteAttribute ("value", Value, true);
                        Attributes.Remove ("value");
                        base.RenderAttributes (writer);
                }
-#if NET_2_0
+               
                protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
                {
-                       return DefaultLoadPostData (postDataKey, postCollection);
+                       bool checkedOnClient = postCollection [Name] == Value;
+                       if (Checked == checkedOnClient)
+                               return false;
+
+                       ValidateEvent (UniqueID, Value);
+                       Checked = checkedOnClient;
+                       return checkedOnClient;
                }
 
                protected virtual void RaisePostDataChangedEvent ()
                {
                        OnServerChange (EventArgs.Empty);
                }
-#endif
-
-               internal bool DefaultLoadPostData (string postDataKey, NameValueCollection postCollection)
-               {
-                       string s = postCollection [postDataKey];
-                       if ((s != null) && (Attributes ["value"] != postDataKey)) {
-                               Attributes ["value"] = postDataKey;
-                               // this doesn't seems to trigger a change
-                       }
-                       return false;
-               }
 
                bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
                {
-#if NET_2_0
                        return LoadPostData (postDataKey, postCollection);
-#else
-                       return DefaultLoadPostData (postDataKey, postCollection);
-#endif
                }
 
                void IPostBackDataHandler.RaisePostDataChangedEvent ()
                {
-#if NET_2_0
                        RaisePostDataChangedEvent ();
-#else
-                       OnServerChange (EventArgs.Empty);
-#endif
                }