diff options
author | Marek Safar <marek.safar@gmail.com> | 2018-05-30 01:31:51 +0300 |
---|---|---|
committer | Alexander Köplinger <alex.koeplinger@outlook.com> | 2018-05-30 01:31:51 +0300 |
commit | f37db9cf903ac50c4ab0d69a942a45de2ece0943 (patch) | |
tree | cd34b66243c2f453cae066801fb01ee4e568d203 /mcs/class/System.Web | |
parent | 6a7bd7be2721c7e7cd45709b1d3b3185e9713c6a (diff) |
[System.Web] Fix bug with not preserving state of CheckBoxList after postback because of value beeing rendered (#8928)
Diffstat (limited to 'mcs/class/System.Web')
4 files changed, 53 insertions, 16 deletions
diff --git a/mcs/class/System.Web/Makefile b/mcs/class/System.Web/Makefile index dd0a0f017ef..e8693e46d39 100644 --- a/mcs/class/System.Web/Makefile +++ b/mcs/class/System.Web/Makefile @@ -223,7 +223,8 @@ TEST_RESOURCE_FILES = \ Test/mainsoft/NunitWebResources/CheckBoxList_Bug600415.aspx \ Test/mainsoft/NunitWebResources/BoundField_Bug646505.aspx \ Test/mainsoft/NunitWebResources/BoundField_Bug646505.aspx.cs \ - Test/mainsoft/NunitWebResources/HtmlTitleCodeRender_Bug662918.aspx + Test/mainsoft/NunitWebResources/HtmlTitleCodeRender_Bug662918.aspx \ + Test/mainsoft/NunitWebResources/CheckBoxList_CustomValues.aspx RESOURCE_DEFS = \ TranslationResources,resources/TranslationResources.resx diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/CheckBoxList.cs b/mcs/class/System.Web/System.Web.UI.WebControls/CheckBoxList.cs index 7cb9ba78c57..76691259e9f 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/CheckBoxList.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/CheckBoxList.cs @@ -192,10 +192,17 @@ namespace System.Web.UI.WebControls if (checkbox == -1) return false; - string val = postCollection [postDataKey]; - bool ischecked = val == "on"; + ListItem item = Items [checkbox]; + if (item.Enabled) { + string val = postCollection [postDataKey]; + bool ischecked = val == "on"; +#if NET_4_0 + if (!RenderingCompatibilityLessThan40) { + ischecked = val == item.Value; + } +#endif if (ischecked && !item.Selected) { item.Selected = true; return true; diff --git a/mcs/class/System.Web/Test/System.Web.UI.WebControls/CheckBoxListTest.cs b/mcs/class/System.Web/Test/System.Web.UI.WebControls/CheckBoxListTest.cs index afa86b38350..67cce42930d 100644 --- a/mcs/class/System.Web/Test/System.Web.UI.WebControls/CheckBoxListTest.cs +++ b/mcs/class/System.Web/Test/System.Web.UI.WebControls/CheckBoxListTest.cs @@ -37,6 +37,7 @@ using System.Web.UI; using System.Web.UI.WebControls; using System.Drawing; using System.Collections; +using System.Text.RegularExpressions; using MonoTests.SystemWeb.Framework; using MonoTests.stand_alone.WebHarness; using System.Collections.Specialized; @@ -133,6 +134,7 @@ namespace MonoTests.System.Web.UI.WebControls { WebTest.CopyResource (t, "CheckBoxList_Bug377703_2.aspx", "CheckBoxList_Bug377703_2.aspx"); WebTest.CopyResource (t, "CheckBoxList_Bug578770.aspx", "CheckBoxList_Bug578770.aspx"); WebTest.CopyResource (t, "CheckBoxList_Bug600415.aspx", "CheckBoxList_Bug600415.aspx"); + WebTest.CopyResource (t, "CheckBoxList_CustomValues.aspx", "CheckBoxList_CustomValues.aspx"); } [Test] @@ -156,6 +158,20 @@ namespace MonoTests.System.Web.UI.WebControls { } [Test] + [Category("NunitWeb")] + public void CheckBoxList_CustomValues(){ + WebTest t = new WebTest("CheckBoxList_CustomValues.aspx"); + string html = t.Run(); + FormRequest f = new FormRequest(t.Response, "form1"); + f.Controls.Add ("checkBoxList$1"); + f.Controls ["checkBoxList$1"].Value = "val2"; + t.Request = f; + html = t.Run(); + Regex countchecked = new Regex("<input[^>]*checked=\"checked\"[^>]*>"); + Assert.AreEqual(1, countchecked.Matches(html).Count); + } + + [Test] public void CheckBoxList_Bug377703_1 () { WebTest t = new WebTest ("CheckBoxList_Bug377703_1.aspx"); @@ -169,8 +185,7 @@ namespace MonoTests.System.Web.UI.WebControls { FormRequest fr = new FormRequest (t.Response, "form1"); fr.Controls.Add ("cbxl1$0"); - fr.Controls ["cbxl1$0"].Value = "on"; - + fr.Controls ["cbxl1$0"].Value = "x"; fr.Controls.Add ("ctl01"); fr.Controls ["ctl01"].Value = "Click me twice to have the first Item become empty"; @@ -179,8 +194,7 @@ namespace MonoTests.System.Web.UI.WebControls { fr = new FormRequest (t.Response, "form1"); fr.Controls.Add ("cbxl1$0"); - fr.Controls ["cbxl1$0"].Value = "on"; - + fr.Controls ["cbxl1$0"].Value = "x"; fr.Controls.Add ("ctl01"); fr.Controls ["ctl01"].Value = "Click me twice to have the first Item become empty"; @@ -220,11 +234,9 @@ namespace MonoTests.System.Web.UI.WebControls { FormRequest fr = new FormRequest (t.Response, "form1"); fr.Controls.Add ("cbxl2$0"); - fr.Controls ["cbxl2$0"].Value = "on"; - + fr.Controls ["cbxl2$0"].Value = "x"; fr.Controls.Add ("cbxl2$2"); - fr.Controls ["cbxl2$2"].Value = "on"; - + fr.Controls ["cbxl2$2"].Value = "z"; fr.Controls.Add ("ctl01"); fr.Controls ["ctl01"].Value = "Click to toggle enable status above"; @@ -305,14 +317,13 @@ namespace MonoTests.System.Web.UI.WebControls { fr = new FormRequest (t.Response, "form1"); fr.Controls.Add ("checkBoxList$0"); - fr.Controls ["checkBoxList$0"].Value = "on"; + fr.Controls ["checkBoxList$0"].Value = "Item 1"; fr.Controls.Add ("checkBoxList$1"); - fr.Controls ["checkBoxList$1"].Value = "on"; + fr.Controls ["checkBoxList$1"].Value = "Item 2"; fr.Controls.Add ("checkBoxList$2"); - fr.Controls ["checkBoxList$2"].Value = "on"; + fr.Controls ["checkBoxList$2"].Value = "Item 3"; fr.Controls.Add ("checkBoxList$3"); - fr.Controls ["checkBoxList$3"].Value = "on"; - + fr.Controls ["checkBoxList$3"].Value = "Item 4"; t.Request = fr; html = t.Run (); listHtml = HtmlDiff.GetControlFromPageHtml (html); diff --git a/mcs/class/System.Web/Test/mainsoft/NunitWebResources/CheckBoxList_CustomValues.aspx b/mcs/class/System.Web/Test/mainsoft/NunitWebResources/CheckBoxList_CustomValues.aspx new file mode 100644 index 00000000000..64d90f884d4 --- /dev/null +++ b/mcs/class/System.Web/Test/mainsoft/NunitWebResources/CheckBoxList_CustomValues.aspx @@ -0,0 +1,18 @@ +<%@ Page Language="C#" %> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<title>Value attribute on items</title> +</head> +<body> +<form id="form1" runat="server" method="post"> +<%= MonoTests.stand_alone.WebHarness.HtmlDiff.BEGIN_TAG %> + <asp:CheckBoxList id="checkBoxList" runat="server"> + <asp:ListItem Value="val1" Selected="true">Text1</asp:ListItem> + <asp:ListItem Value="val2">Text2</asp:ListItem> + <asp:ListItem Value="val3" Selected="true">Text3</asp:ListItem> + </asp:CheckBoxList> +<%= MonoTests.stand_alone.WebHarness.HtmlDiff.END_TAG %> +</form> +</body> +</html> |