2007-05-07 Igor Zelmanovich <igorz@mainsoft.com>
authorIgor Zelmanovich <igorz@mono-cvs.ximian.com>
Mon, 7 May 2007 08:49:07 +0000 (08:49 -0000)
committerIgor Zelmanovich <igorz@mono-cvs.ximian.com>
Mon, 7 May 2007 08:49:07 +0000 (08:49 -0000)
* MenuItem.cs: fixed:
when 'Value' property is not set, value of 'Text' property is used
instead and vice versa.

* MenuTest.cs:
new tests were added.

svn path=/trunk/mcs/; revision=76809

mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
mcs/class/System.Web/System.Web.UI.WebControls/MenuItem.cs
mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog
mcs/class/System.Web/Test/System.Web.UI.WebControls/MenuTest.cs

index 90cca3a388537ec102a38dc06288825ef7f24401..4857ab51721ac8fc799548791c055f5bc22e691a 100644 (file)
@@ -1,3 +1,9 @@
+2007-05-07 Igor Zelmanovich <igorz@mainsoft.com>
+
+       * MenuItem.cs: fixed: 
+       when 'Value' property is not set, value of 'Text' property is used 
+       instead and vice versa.
+
 2007-05-06 Igor Zelmanovich <igorz@mainsoft.com>
 
        * TreeNode.cs: fixed: 
index 3c6a56c58a62744aa95d79568b5855567750b416..fe3c03955cb0aabb29ed8fbd94b0f82bbfba7087 100644 (file)
@@ -218,7 +218,12 @@ namespace System.Web.UI.WebControls
                [DefaultValue ("")]
                public string Text {
                        get {
-                               return ViewState ["Text"] == null ? String.Empty : (String) ViewState ["Text"];
+                               object o = ViewState ["Text"];
+                               if (o == null)
+                                       o = ViewState ["Value"];
+                               if (o != null)
+                                       return (string) o;
+                               return String.Empty;
                        }
                        set {
                                ViewState ["Text"] = value;
@@ -240,7 +245,12 @@ namespace System.Web.UI.WebControls
                [DefaultValue ("")]
                public string Value {
                        get {
-                               return ViewState ["Value"] == null ? String.Empty : (String) ViewState ["Value"];
+                               object o = ViewState ["Value"];
+                               if (o == null)
+                                       o = ViewState ["Text"];
+                               if (o != null)
+                                       return (string) o;
+                               return String.Empty;
                        }
                        set {
                                ViewState ["Value"] = value;
@@ -502,38 +512,36 @@ namespace System.Web.UI.WebControls
                                        ToolTip = bin.ToolTip;
 
                                // Bind Value property
-
+                               string value = null;
                                if (bin.ValueField.Length > 0) {
-                                       Value = Convert.ToString (GetBoundPropertyValue (bin.ValueField));
-                                       if (Value.Length == 0)
-                                               Value = bin.Value;
-                                       if (Value.Length == 0)
-                                               Value = bin.Text;
+                                       value = Convert.ToString (GetBoundPropertyValue (bin.ValueField));
                                }
-                               else if (bin.Value.Length > 0)
-                                       Value = bin.Value;
-                               else if (bin.Text.Length > 0)
-                                       Value = bin.Text;
-                               else
-                                       Value = GetDefaultBoundText ();
-                               
-                               // Bind Text property
+                               if (String.IsNullOrEmpty (value)) {
+                                       if (bin.Value.Length > 0)
+                                               value = bin.Value;
+                                       else if (bin.Text.Length > 0)
+                                               value = bin.Text;
+                                       else
+                                               value = String.Empty;
+                               }
+                               Value = value;
 
+                               // Bind Text property
+                               string text = null;
                                if (bin.TextField.Length > 0) {
-                                       Text = Convert.ToString (GetBoundPropertyValue (bin.TextField));
+                                       text = Convert.ToString (GetBoundPropertyValue (bin.TextField));
                                        if (bin.FormatString.Length > 0)
-                                               Text = string.Format (bin.FormatString, Text);
-                                       if (Text.Length == 0)
-                                               Text = bin.Text;
-                                       if (Text.Length == 0)
-                                               Text = bin.Value;
+                                               text = string.Format (bin.FormatString, text);
                                }
-                               else if (bin.Text.Length > 0)
-                                       Text = bin.Text;
-                               else if (bin.Value.Length > 0)
-                                       Text = bin.Value;
-                               else
-                                       Text = GetDefaultBoundText ();
+                               if (String.IsNullOrEmpty (text)) {
+                                       if (bin.Text.Length > 0)
+                                               text = bin.Text;
+                                       else if (bin.Value.Length > 0)
+                                               text = bin.Value;
+                                       else
+                                               text = String.Empty;
+                               }
+                               Text = text;
 
                        }
                        else {
index 88632e335606c50b80cb7f8acb89a6f89fc4f223..b786264c3d0e92714ec82a05cfe3718a1a775a30 100644 (file)
@@ -1,3 +1,8 @@
+2007-05-07 Igor Zelmanovich <igorz@mainsoft.com>
+
+       * MenuTest.cs:
+       new tests were added.   
+
 2007-05-06 Igor Zelmanovich <igorz@mainsoft.com>
 
        * TreeNodeTest.cs:
index b98fc252165f9d4a34c200b32df46b62a60dee88..f35ac63b61047c1ee54a8900adbb8a1f9d68205b 100644 (file)
@@ -1544,6 +1544,30 @@ namespace MonoTests.System.Web.UI.WebControls
                        m.Items [0].ChildItems.Add (new MenuItem ());\r
                        m.Items [0].ChildItems [0].ChildItems.Add (new MenuItem ());\r
                }\r
+\r
+               [Test]\r
+               public void MenuItem_TextValue1 ()\r
+               {\r
+                       MenuItem item = new MenuItem ();\r
+                       item.Text = "TTT";\r
+                       Assert.AreEqual ("TTT", item.Value, "MenuItem_TextValue1#1");\r
+                       item.Value = "";\r
+                       Assert.AreEqual ("", item.Value, "MenuItem_TextValue1#2");\r
+                       item.Value = null;\r
+                       Assert.AreEqual ("TTT", item.Value, "MenuItem_TextValue1#3");\r
+               }\r
+\r
+               [Test]\r
+               public void MenuItem_TextValue2 ()\r
+               {\r
+                       MenuItem item = new MenuItem ();\r
+                       item.Value = "VVV";\r
+                       Assert.AreEqual ("VVV", item.Text, "MenuItem_TextValue2#1");\r
+                       item.Text = "";\r
+                       Assert.AreEqual ("", item.Text, "MenuItem_TextValue2#2");\r
+                       item.Text = null;\r
+                       Assert.AreEqual ("VVV", item.Text, "MenuItem_TextValue2#3");\r
+               }\r
        }\r
 }\r
 #endif\r