Use UNIX line endings consistently
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / RadioButton.cs
index 86b5649ba26e8f5073178bd0ce932230ceccff5c..2f5ceaf2c1770f0ae8f58f184e8f212566d8cbc1 100644 (file)
@@ -68,19 +68,37 @@ namespace System.Web.UI.WebControls {
                        get {
                                string unique = UniqueID;
                                string gn = GroupName;
+                               if (gn.Length == 0)
+                                       return unique;
                                int colon = -1;
-                               if (unique != null)
-                                       colon = unique.IndexOf (':');
+                               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;
                        }
                }
 
                internal string ValueAttribute {
                        get {
-                               return ViewState.GetString ("Value", String.Empty);
+                               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;
@@ -89,11 +107,13 @@ namespace System.Web.UI.WebControls {
 
                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);
-                       string val = ValueAttribute;
-                       if (val == null || val.Length == 0)
-                               val = UniqueID;
-                       w.AddAttribute (HtmlTextWriterAttribute.Value, val);
+                       w.AddAttribute (HtmlTextWriterAttribute.Value, ValueAttribute);
                }
 
 #if NET_2_0
@@ -111,33 +131,27 @@ namespace System.Web.UI.WebControls {
 #endif
                bool LoadPostData (string postDataKey, NameValueCollection postCollection) 
                {
-                       bool old_checked = Checked;
-                       
-                       if (postCollection[NameAttribute] == postDataKey) {
-                               Checked = true;
-                       } else {
-                               Checked = false;
-                       }
+                       string value = postCollection [NameAttribute];
+                       bool checkedOnClient = value == ValueAttribute;
+#if NET_2_0
+                       ValidateEvent (NameAttribute, value);
+#endif
+                       if (Checked == checkedOnClient)
+                               return false;
 
-                       if (old_checked != Checked) {
-                               return (true);
-                       } else {
-                               return (false);
-                       }
+                       Checked = checkedOnClient;
+                       return checkedOnClient;                 
                }
 
 #if NET_2_0
-               protected override
-#endif
-               void RaisePostDataChangedEvent ()
+               protected override void RaisePostDataChangedEvent ()
                {
-#if NET_2_0
                        if (CausesValidation)
                                Page.Validate (ValidationGroup);
-#endif
                        OnCheckedChanged (EventArgs.Empty);
                }
-
+#endif
+               
                bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
                {
                        return LoadPostData (postDataKey, postCollection);