Ver Fonte

2007-05-07 Igor Zelmanovich <[email protected]>

	* 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
Igor Zelmanovich há 18 anos atrás
pai
commit
676b57792a

+ 6 - 0
mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,9 @@
+2007-05-07 Igor Zelmanovich <[email protected]>
+
+	* MenuItem.cs: fixed: 
+	when 'Value' property is not set, value of 'Text' property is used 
+	instead and vice versa.
+
 2007-05-06 Igor Zelmanovich <[email protected]>
 
 	* TreeNode.cs: fixed: 

+ 36 - 28
mcs/class/System.Web/System.Web.UI.WebControls/MenuItem.cs

@@ -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 {

+ 5 - 0
mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,8 @@
+2007-05-07 Igor Zelmanovich <[email protected]>
+
+	* MenuTest.cs:
+	new tests were added.	
+
 2007-05-06 Igor Zelmanovich <[email protected]>
 
 	* TreeNodeTest.cs:

+ 24 - 0
mcs/class/System.Web/Test/System.Web.UI.WebControls/MenuTest.cs

@@ -1544,6 +1544,30 @@ namespace MonoTests.System.Web.UI.WebControls
 			m.Items [0].ChildItems.Add (new MenuItem ());
 			m.Items [0].ChildItems [0].ChildItems.Add (new MenuItem ());
 		}
+
+		[Test]
+		public void MenuItem_TextValue1 ()
+		{
+			MenuItem item = new MenuItem ();
+			item.Text = "TTT";
+			Assert.AreEqual ("TTT", item.Value, "MenuItem_TextValue1#1");
+			item.Value = "";
+			Assert.AreEqual ("", item.Value, "MenuItem_TextValue1#2");
+			item.Value = null;
+			Assert.AreEqual ("TTT", item.Value, "MenuItem_TextValue1#3");
+		}
+
+		[Test]
+		public void MenuItem_TextValue2 ()
+		{
+			MenuItem item = new MenuItem ();
+			item.Value = "VVV";
+			Assert.AreEqual ("VVV", item.Text, "MenuItem_TextValue2#1");
+			item.Text = "";
+			Assert.AreEqual ("", item.Text, "MenuItem_TextValue2#2");
+			item.Text = null;
+			Assert.AreEqual ("VVV", item.Text, "MenuItem_TextValue2#3");
+		}
 	}
 }
 #endif