From 2d668e958307399970ff9e17e8972ae692413f2b Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Mon, 21 Jun 2010 18:41:51 +0000 Subject: [PATCH] 2010-06-21 Marek Habersack * BaseValidator.cs, BulletedList.cs, Calendar.cs, CheckBox.cs, CheckBoxList.cs, DataGrid.cs, DropDownList.cs, GridView.cs, HyperLink.cs, ImageButton.cs, LinkButton.cs, ListBox.cs, ListControl.cs, Menu.cs, RadioButton.cs, RadioButtonList.cs, RepeatInfo.cs, Repeater.cs, TextBox.cs, TreeView.cs, ValidationSummary.cs, WebControl.cs: use WebControl.IsEnabled instead of Enabled wherever necessary. svn path=/trunk/mcs/; revision=159280 --- .../BaseValidator.cs | 8 +- .../System.Web.UI.WebControls/BulletedList.cs | 8 +- .../System.Web.UI.WebControls/Calendar.cs | 35 ++++----- .../System.Web.UI.WebControls/ChangeLog | 10 +++ .../System.Web.UI.WebControls/CheckBox.cs | 25 +++--- .../System.Web.UI.WebControls/CheckBoxList.cs | 2 +- .../System.Web.UI.WebControls/DataGrid.cs | 2 +- .../System.Web.UI.WebControls/DropDownList.cs | 2 +- .../System.Web.UI.WebControls/GridView.cs | 3 +- .../System.Web.UI.WebControls/HyperLink.cs | 2 +- .../System.Web.UI.WebControls/ImageButton.cs | 5 +- .../System.Web.UI.WebControls/LinkButton.cs | 20 ++--- .../System.Web.UI.WebControls/ListBox.cs | 5 +- .../System.Web.UI.WebControls/ListControl.cs | 5 +- .../System.Web.UI.WebControls/Menu.cs | 2 +- .../System.Web.UI.WebControls/RadioButton.cs | 4 +- .../RadioButtonList.cs | 2 +- .../System.Web.UI.WebControls/RepeatInfo.cs | 2 +- .../System.Web.UI.WebControls/Repeater.cs | 12 +-- .../System.Web.UI.WebControls/TextBox.cs | 2 +- .../System.Web.UI.WebControls/TreeView.cs | 36 ++++----- .../ValidationSummary.cs | 2 +- .../System.Web.UI.WebControls/WebControl.cs | 12 ++- .../System.Web_standalone_test.dll.sources | 1 + .../WebControlsMustUseIsEnabled_Bug571715.cs | 65 ++++++++++++++++ .../People.xml | 7 ++ .../default.aspx | 29 +++++++ .../web.config | 76 +++++++++++++++++++ 28 files changed, 292 insertions(+), 92 deletions(-) create mode 100644 mcs/class/System.Web/Test/standalone-tests/WebControlsMustUseIsEnabled_Bug571715.cs create mode 100644 mcs/class/System.Web/Test/standalone/WebControlsMustUseIsEnabled_Bug571715/People.xml create mode 100644 mcs/class/System.Web/Test/standalone/WebControlsMustUseIsEnabled_Bug571715/default.aspx create mode 100644 mcs/class/System.Web/Test/standalone/WebControlsMustUseIsEnabled_Bug571715/web.config diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/BaseValidator.cs b/mcs/class/System.Web/System.Web.UI.WebControls/BaseValidator.cs index 0d704ffa983..8ec6ceaef39 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/BaseValidator.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/BaseValidator.cs @@ -234,7 +234,7 @@ namespace System.Web.UI.WebControls { if (SetFocusOnError) RegisterExpandoAttribute (ClientID, "focusOnError", "t"); #endif - if (!Enabled) + if (!IsEnabled) #if NET_2_0 RegisterExpandoAttribute (ClientID, "enabled", "False"); #else @@ -242,7 +242,7 @@ namespace System.Web.UI.WebControls { #endif #if NET_2_0 - if (Enabled && !IsValid) { + if (IsEnabled && !IsValid) { RegisterExpandoAttribute (ClientID, "isvalid", "False"); #else if (!IsValid) { @@ -510,7 +510,7 @@ document.getElementById('" + ClientID + @"').dispose = function() { override void Render (HtmlTextWriter writer) { #if NET_2_0 - if (!Enabled && !EnableClientScript) + if (!IsEnabled && !EnableClientScript) return; #endif if (render_uplevel) { @@ -576,7 +576,7 @@ document.getElementById('" + ClientID + @"').dispose = function() { #endif void Validate () { - if (Enabled && Visible) + if (IsEnabled && Visible) IsValid = ControlPropertiesValid () && EvaluateIsValid (); else IsValid = true; diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/BulletedList.cs b/mcs/class/System.Web/System.Web.UI.WebControls/BulletedList.cs index fac29e6d7e0..443fb2db3f0 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/BulletedList.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/BulletedList.cs @@ -131,9 +131,9 @@ namespace System.Web.UI.WebControls { break; case BulletedListDisplayMode.HyperLink: - if (Enabled && item.Enabled) { + if (IsEnabled && item.Enabled) { writer.AddAttribute (HtmlTextWriterAttribute.Href, item.Value); - if (Target != "") + if (Target.Length > 0) writer.AddAttribute(HtmlTextWriterAttribute.Target, this.Target); } @@ -146,7 +146,7 @@ namespace System.Web.UI.WebControls { break; case BulletedListDisplayMode.LinkButton: - if (Enabled && item.Enabled) + if (IsEnabled && item.Enabled) writer.AddAttribute (HtmlTextWriterAttribute.Href, Page.ClientScript.GetPostBackEventReference (GetPostBackOptions (index.ToString (Helpers.InvariantCulture)), true)); else writer.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled", false); @@ -301,7 +301,7 @@ namespace System.Web.UI.WebControls { [DefaultValueAttribute ("")] [TypeConverter (typeof (TargetConverter))] public virtual string Target { - get { return ViewState.GetString ("Target", ""); } + get { return ViewState.GetString ("Target", String.Empty); } set { ViewState ["Target"] = value; } } diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/Calendar.cs b/mcs/class/System.Web/System.Web.UI.WebControls/Calendar.cs index 15eb1fb1ec0..3f799e53446 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/Calendar.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/Calendar.cs @@ -818,17 +818,18 @@ namespace System.Web.UI.WebControls { writer.RenderBeginTag (HtmlTextWriterTag.Table); #if NET_2_0 - if (Caption != "") + if (!String.IsNullOrEmpty (Caption)) WriteCaption (writer); #endif - + bool enabled = IsEnabled; + if (ShowTitle) - WriteTitle (writer); - + WriteTitle (writer, enabled); + if (ShowDayHeader) - WriteDayHeader (writer); + WriteDayHeader (writer, enabled); - WriteDays (writer); + WriteDays (writer, enabled); writer.RenderEndTag (); } @@ -914,7 +915,7 @@ namespace System.Web.UI.WebControls { // // Private methods // - void WriteDayHeader (HtmlTextWriter writer) + void WriteDayHeader (HtmlTextWriter writer, bool enabled) { int i, first; string dayName; @@ -942,7 +943,7 @@ namespace System.Web.UI.WebControls { int days = DateTime.DaysInMonth (DisplayDate.Year, DisplayDate.Month); selector.RenderBeginTag (writer); - writer.Write (BuildLink ("R" + GetDaysFromZenith (date) + days, SelectMonthText, DayHeaderStyle.ForeColor, Enabled)); + writer.Write (BuildLink ("R" + GetDaysFromZenith (date) + days, SelectMonthText, DayHeaderStyle.ForeColor, enabled)); selector.RenderEndTag (writer); } } @@ -1003,7 +1004,7 @@ namespace System.Web.UI.WebControls { writer.RenderEndTag (); } - void WriteDay (DateTime date, HtmlTextWriter writer) + void WriteDay (DateTime date, HtmlTextWriter writer, bool enabled) { TableItemStyle style = new TableItemStyle (); TableCell cell = new TableCell (); @@ -1039,7 +1040,7 @@ namespace System.Web.UI.WebControls { style.CopyFrom (otherMonthDayStyle); } - if (day.IsSelected && Enabled) { + if (enabled && day.IsSelected) { style.BackColor = Color.Silver; style.ForeColor = Color.White; if (selectedDayStyle != null && !selectedDayStyle.IsEmpty) { @@ -1050,12 +1051,12 @@ namespace System.Web.UI.WebControls { cell.ApplyStyle (style); lit.Text = BuildLink (GetDaysFromZenith (date).ToString (), day.DayNumberText, - cell.ForeColor, day.IsSelectable && Enabled); + cell.ForeColor, enabled && day.IsSelectable); cell.RenderControl (writer); } - void WriteDays (HtmlTextWriter writer) + void WriteDays (HtmlTextWriter writer, bool enabled) { DateTime date = new DateTime (DisplayDate.Year, DisplayDate.Month, 1); // first date DateTime lastDate; @@ -1087,12 +1088,12 @@ namespace System.Web.UI.WebControls { } selectorCell.RenderBeginTag (writer); - writer.Write (BuildLink ("R" + GetDaysFromZenith (date) + "07", SelectWeekText, selectorCell.ForeColor, Enabled)); + writer.Write (BuildLink ("R" + GetDaysFromZenith (date) + "07", SelectWeekText, selectorCell.ForeColor, enabled)); selectorCell.RenderEndTag (writer); } for (int i = 0; i < daysInAWeek; i++) { - WriteDay (date, writer); + WriteDay (date, writer, enabled); date = GetGlobalCalendar().AddDays (date, 1); } @@ -1156,7 +1157,7 @@ namespace System.Web.UI.WebControls { } #endif - void WriteTitle (HtmlTextWriter writer) + void WriteTitle (HtmlTextWriter writer, bool enabled) { TableCell cellNextPrev = null; TableCell titleCell = new TableCell (); @@ -1191,7 +1192,7 @@ namespace System.Web.UI.WebControls { DateTime date = GetGlobalCalendar().AddMonths (DisplayDate, - 1); date = GetGlobalCalendar ().AddDays (date, -date.Day + 1); cellNextPrev.RenderBeginTag (writer); - writer.Write (BuildLink ("V" + GetDaysFromZenith (date), GetNextPrevFormatText (date, false), cellNextPrev.ForeColor, Enabled)); + writer.Write (BuildLink ("V" + GetDaysFromZenith (date), GetNextPrevFormatText (date, false), cellNextPrev.ForeColor, enabled)); cellNextPrev.RenderEndTag (writer); } @@ -1220,7 +1221,7 @@ namespace System.Web.UI.WebControls { cellNextPrev.HorizontalAlign = HorizontalAlign.Right; cellNextPrev.RenderBeginTag (writer); - writer.Write (BuildLink ("V" + GetDaysFromZenith (date), GetNextPrevFormatText (date, true), cellNextPrev.ForeColor, Enabled)); + writer.Write (BuildLink ("V" + GetDaysFromZenith (date), GetNextPrevFormatText (date, true), cellNextPrev.ForeColor, enabled)); cellNextPrev.RenderEndTag (writer); } diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog b/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog index ed03efa99da..a44a6d0cff8 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog +++ b/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog @@ -1,3 +1,13 @@ +2010-06-21 Marek Habersack + + * BaseValidator.cs, BulletedList.cs, Calendar.cs, CheckBox.cs, + CheckBoxList.cs, DataGrid.cs, DropDownList.cs, GridView.cs, + HyperLink.cs, ImageButton.cs, LinkButton.cs, ListBox.cs, + ListControl.cs, Menu.cs, RadioButton.cs, RadioButtonList.cs, + RepeatInfo.cs, Repeater.cs, TextBox.cs, TreeView.cs, + ValidationSummary.cs, WebControl.cs: use WebControl.IsEnabled + instead of Enabled wherever necessary. + 2010-06-16 Marek Habersack * FormView.cs: row values must be retrieved with inclusion of diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/CheckBox.cs b/mcs/class/System.Web/System.Web.UI.WebControls/CheckBox.cs index 733471f379e..78cffc45e72 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/CheckBox.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/CheckBox.cs @@ -299,15 +299,13 @@ namespace System.Web.UI.WebControls { { base.OnPreRender (e); Page page = Page; - bool enabled = Enabled; - if (page != null && enabled) { + if (page != null && IsEnabled) { page.RegisterRequiresPostBack (this); - } #if NET_2_0 - if (Page != null && enabled) page.RegisterEnabledControl (this); #endif + } } static bool IsInputOrCommonAttr (string attname) @@ -393,7 +391,8 @@ namespace System.Web.UI.WebControls { ControlStyle.AddAttributesToRender (w, this); } - if (!Enabled) { + bool enabled = IsEnabled; + if (!enabled) { w.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled", false); need_span = true; } @@ -417,26 +416,26 @@ namespace System.Web.UI.WebControls { TextAlign align = TextAlign; if (align == TextAlign.Right) { - RenderInput (w); + RenderInput (w, enabled); RenderLabel (w); } else { RenderLabel (w); - RenderInput (w); + RenderInput (w, enabled); } if (need_span) w.RenderEndTag (); } - void RenderInput (HtmlTextWriter w) { - + void RenderInput (HtmlTextWriter w, bool enabled) + { if (ClientID != null && ClientID.Length > 0) w.AddAttribute (HtmlTextWriterAttribute.Id, ClientID); w.AddAttribute (HtmlTextWriterAttribute.Type, render_type); string nameAttr = NameAttribute; if (nameAttr != null && nameAttr.Length > 0) w.AddAttribute (HtmlTextWriterAttribute.Name, nameAttr); - InternalAddAttributesToRender (w); + InternalAddAttributesToRender (w, enabled); #if NET_2_0 AddAttributesToRender (w); if (inputAttributes != null) @@ -489,7 +488,7 @@ namespace System.Web.UI.WebControls { #endif bool LoadPostData (string postDataKey, NameValueCollection postCollection) { - if (!Enabled) + if (!IsEnabled) return false; string postedValue = postCollection[postDataKey]; @@ -547,9 +546,9 @@ namespace System.Web.UI.WebControls { } #endif - internal virtual void InternalAddAttributesToRender (HtmlTextWriter w) + internal virtual void InternalAddAttributesToRender (HtmlTextWriter w, bool enabled) { - if (!Enabled) + if (!enabled) w.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled", false); } } 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 f2d419e55a9..c36e159aa24 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/CheckBoxList.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/CheckBoxList.cs @@ -361,7 +361,7 @@ namespace System.Web.UI.WebControls { check_box.AutoPostBack = AutoPostBack; check_box.Checked = item.Selected; check_box.TextAlign = TextAlign; - if (!Enabled) + if (!IsEnabled) check_box.Enabled = false; else check_box.Enabled = item.Enabled; diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/DataGrid.cs b/mcs/class/System.Web/System.Web.UI.WebControls/DataGrid.cs index ec072ab0a33..7be47cb9bc4 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/DataGrid.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/DataGrid.cs @@ -1078,7 +1078,7 @@ namespace System.Web.UI.WebControls { rt.Caption = Caption; rt.CaptionAlign = CaptionAlign; - rt.Enabled = Enabled; + rt.Enabled = IsEnabled; bool top_pager = true; foreach (DataGridItem item in rt.Rows) { diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/DropDownList.cs b/mcs/class/System.Web/System.Web.UI.WebControls/DropDownList.cs index 0db301ac787..4e08f4867b2 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/DropDownList.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/DropDownList.cs @@ -128,7 +128,7 @@ namespace System.Web.UI.WebControls { if (!String.IsNullOrEmpty (UniqueID)) writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID, true); - if (!Enabled && SelectedIndex == -1) + if (!IsEnabled && SelectedIndex == -1) SelectedIndex = 1; #else writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID, true); diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs b/mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs index 26ace72c5ce..fdaaf55ee28 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs @@ -1376,8 +1376,7 @@ namespace System.Web.UI.WebControls } } return 0; - } - else { + } else { GridViewRow footerRow = CreateRow (-1, -1, DataControlRowType.Footer, DataControlRowState.Normal); InitializeRow (footerRow, fields); OnRowCreated (new GridViewRowEventArgs (footerRow)); diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/HyperLink.cs b/mcs/class/System.Web/System.Web.UI.WebControls/HyperLink.cs index b82d2b14ad7..e2e0d9448bb 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/HyperLink.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/HyperLink.cs @@ -59,7 +59,7 @@ namespace System.Web.UI.WebControls { #if NET_2_0 AddDisplayStyleAttribute (w); #endif - if (!Enabled) + if (!IsEnabled) return; // add attributes - only if they're not empty string t = Target; diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/ImageButton.cs b/mcs/class/System.Web/System.Web.UI.WebControls/ImageButton.cs index 2fe68688718..3d766433aca 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/ImageButton.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/ImageButton.cs @@ -371,8 +371,9 @@ namespace System.Web.UI.WebControls { #endif override void OnPreRender (EventArgs e) { - if (Page != null && Enabled) - Page.RegisterRequiresPostBack (this); + Page page = Page; + if (page != null && IsEnabled) + page.RegisterRequiresPostBack (this); } [WebSysDescription ("")] diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/LinkButton.cs b/mcs/class/System.Web/System.Web.UI.WebControls/LinkButton.cs index d6ce63a75e3..1b5e21bf311 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/LinkButton.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/LinkButton.cs @@ -60,9 +60,11 @@ namespace System.Web.UI.WebControls { protected override void AddAttributesToRender (HtmlTextWriter w) { - if (Page != null) - Page.VerifyRenderingInServerForm (this); + Page page = Page; + if (page != null) + page.VerifyRenderingInServerForm (this); + bool enabled = IsEnabled; #if NET_2_0 string onclick = OnClientClick; onclick = ClientScriptManager.EnsureEndsWithSemicolon (onclick); @@ -73,26 +75,26 @@ namespace System.Web.UI.WebControls { if (onclick.Length > 0) w.AddAttribute (HtmlTextWriterAttribute.Onclick, onclick); - - if (Enabled && Page != null) { + + if (enabled && page != null) { PostBackOptions options = GetPostBackOptions (); - string href = Page.ClientScript.GetPostBackEventReference (options, true); + string href = page.ClientScript.GetPostBackEventReference (options, true); w.AddAttribute (HtmlTextWriterAttribute.Href, href); } base.AddAttributesToRender (w); AddDisplayStyleAttribute (w); #else base.AddAttributesToRender (w); - if (Page == null || !Enabled) + if (page == null || !enabled) return; - if (CausesValidation && Page.AreValidatorsUplevel ()) { - ClientScriptManager csm = new ClientScriptManager (Page); + if (CausesValidation && page.AreValidatorsUplevel ()) { + ClientScriptManager csm = new ClientScriptManager (page); w.AddAttribute (HtmlTextWriterAttribute.Href, String.Concat ("javascript:{if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); ", csm.GetPostBackEventReference (this, String.Empty), ";}")); } else { - w.AddAttribute (HtmlTextWriterAttribute.Href, Page.ClientScript.GetPostBackClientHyperlink (this, "")); + w.AddAttribute (HtmlTextWriterAttribute.Href, page.ClientScript.GetPostBackClientHyperlink (this, String.Empty)); } #endif } diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/ListBox.cs b/mcs/class/System.Web/System.Web.UI.WebControls/ListBox.cs index 2586a1ec204..da401fc5d5c 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/ListBox.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/ListBox.cs @@ -208,8 +208,9 @@ namespace System.Web.UI.WebControls { override void OnPreRender (EventArgs e) { base.OnPreRender (e); - if (Page != null && Enabled) - Page.RegisterRequiresPostBack (this); + Page page = Page; + if (page != null && IsEnabled) + page.RegisterRequiresPostBack (this); } #if NET_2_0 diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/ListControl.cs b/mcs/class/System.Web/System.Web.UI.WebControls/ListControl.cs index aad10b02b28..b3800b7a905 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/ListControl.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/ListControl.cs @@ -408,8 +408,9 @@ namespace System.Web.UI.WebControls { { base.OnPreRender (e); #if NET_2_0 - if (Page != null && Enabled) - Page.RegisterEnabledControl (this); + Page page = Page; + if (page != null && IsEnabled) + page.RegisterEnabledControl (this); #endif } diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/Menu.cs b/mcs/class/System.Web/System.Web.UI.WebControls/Menu.cs index 6973243bcfc..53292cc7cb1 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/Menu.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/Menu.cs @@ -903,7 +903,7 @@ namespace System.Web.UI.WebControls protected internal virtual void RaisePostBackEvent (string eventArgument) { ValidateEvent (UniqueID, eventArgument); - if (!Enabled) + if (!IsEnabled) return; EnsureChildControls(); diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/RadioButton.cs b/mcs/class/System.Web/System.Web.UI.WebControls/RadioButton.cs index 2f5ceaf2c17..85ea99d49c6 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/RadioButton.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/RadioButton.cs @@ -105,14 +105,14 @@ namespace System.Web.UI.WebControls { } } - internal override void InternalAddAttributesToRender (HtmlTextWriter w) + internal override void InternalAddAttributesToRender (HtmlTextWriter w, bool enabled) { #if NET_2_0 Page page = Page; if (page != null) page.ClientScript.RegisterForEventValidation (NameAttribute, ValueAttribute); #endif - base.InternalAddAttributesToRender (w); + base.InternalAddAttributesToRender (w, enabled); w.AddAttribute (HtmlTextWriterAttribute.Value, ValueAttribute); } diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/RadioButtonList.cs b/mcs/class/System.Web/System.Web.UI.WebControls/RadioButtonList.cs index b8ee5afaf28..df98ac8028f 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/RadioButtonList.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/RadioButtonList.cs @@ -255,7 +255,7 @@ namespace System.Web.UI.WebControls { radio.Checked = item.Selected; radio.ValueAttribute = item.Value; radio.AutoPostBack = AutoPostBack; - radio.Enabled = Enabled; + radio.Enabled = IsEnabled; radio.TabIndex = tabIndex; #if NET_2_0 radio.ValidationGroup = ValidationGroup; diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/RepeatInfo.cs b/mcs/class/System.Web/System.Web.UI.WebControls/RepeatInfo.cs index e86d9bbda33..b1e275a8218 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/RepeatInfo.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/RepeatInfo.cs @@ -414,7 +414,7 @@ namespace System.Web.UI.WebControls { c.ID = wc.ClientID; c.CopyBaseAttributes (wc); c.ApplyStyle (s); - c.Enabled = wc.Enabled; + c.Enabled = wc.IsEnabled; c.RenderBeginTag (w); } diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/Repeater.cs b/mcs/class/System.Web/System.Web.UI.WebControls/Repeater.cs index e99f1ede0d1..499143e7e6e 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/Repeater.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/Repeater.cs @@ -533,10 +533,11 @@ namespace System.Web.UI.WebControls { protected internal override void OnInit (EventArgs e) { base.OnInit (e); - if (Page != null) { - Page.PreLoad += new EventHandler (OnPagePreLoad); + Page page = Page; + if (page != null) { + page.PreLoad += new EventHandler (OnPagePreLoad); - if (!IsViewStateEnabled && Page.IsPostBack) + if (!IsViewStateEnabled && page.IsPostBack) RequiresDataBinding = true; } } @@ -556,8 +557,9 @@ namespace System.Web.UI.WebControls { void Initialize () { - if (Page != null) { - if (!Page.IsPostBack || (IsViewStateEnabled && (ViewState ["Items"] == null))) + Page page = Page; + if (page != null) { + if (!page.IsPostBack || (IsViewStateEnabled && (ViewState ["Items"] == null))) RequiresDataBinding = true; } diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/TextBox.cs b/mcs/class/System.Web/System.Web.UI.WebControls/TextBox.cs index d072f9a42c8..f1b447e85d0 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/TextBox.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/TextBox.cs @@ -195,7 +195,7 @@ namespace System.Web.UI.WebControls { } Page page = Page; - if (page != null && Enabled) + if (page != null && IsEnabled) page.RegisterEnabledControl (this); #endif } diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/TreeView.cs b/mcs/class/System.Web/System.Web.UI.WebControls/TreeView.cs index 1716ee8709d..08d3b07d8e5 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/TreeView.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/TreeView.cs @@ -1086,13 +1086,14 @@ namespace System.Web.UI.WebControls { base.OnPreRender (e); - if (Page != null) { - if (Enabled) - Page.RegisterRequiresPostBack (this); + Page page = Page; + if (page != null) { + if (IsEnabled) + page.RegisterRequiresPostBack (this); - if (EnableClientScript && !Page.ClientScript.IsClientScriptIncludeRegistered (typeof(TreeView), "TreeView.js")) { - string url = Page.ClientScript.GetWebResourceUrl (typeof(TreeView), "TreeView.js"); - Page.ClientScript.RegisterClientScriptInclude (typeof(TreeView), "TreeView.js", url); + if (EnableClientScript && !page.ClientScript.IsClientScriptIncludeRegistered (typeof(TreeView), "TreeView.js")) { + string url = page.ClientScript.GetWebResourceUrl (typeof(TreeView), "TreeView.js"); + page.ClientScript.RegisterClientScriptInclude (typeof(TreeView), "TreeView.js", url); } } @@ -1117,11 +1118,11 @@ namespace System.Web.UI.WebControls ClientScriptManager.GetScriptLiteral (GetNodeImageUrl ("noexpand", imageStyle))); } - if (Page != null) { + if (page != null) { script.AppendFormat (_OnPreRender_Script_PopulateCallback, ctree, - Page.theForm, - Page.WebFormScriptReference); + page.theForm, + page.WebFormScriptReference); // Page.ClientScript.GetCallbackEventReference ( // "this.uid", "nodeId", @@ -1134,23 +1135,24 @@ namespace System.Web.UI.WebControls ClientScriptManager.GetScriptLiteral (GetNodeImageToolTip (true, null)), ClientScriptManager.GetScriptLiteral (GetNodeImageToolTip (false, null))); - if (!Page.IsPostBack) + if (!page.IsPostBack) SetNodesExpandedToDepthRecursive (Nodes); - if (EnableClientScript) { - Page.ClientScript.RegisterHiddenField (ClientID + "_ExpandStates", GetExpandStates ()); + bool enableClientScript = EnableClientScript; + if (enableClientScript) { + page.ClientScript.RegisterHiddenField (ClientID + "_ExpandStates", GetExpandStates ()); // Make sure the basic script infrastructure is rendered - Page.ClientScript.RegisterWebFormClientScript (); + page.ClientScript.RegisterWebFormClientScript (); } - if (EnableClientScript && PopulateNodesFromClient) - Page.ClientScript.RegisterHiddenField (ClientID + "_PopulatedStates", "|"); + if (enableClientScript && PopulateNodesFromClient) + page.ClientScript.RegisterHiddenField (ClientID + "_PopulatedStates", "|"); EnsureStylesPrepared (); if (hoverNodeStyle != null) { - if (Page.Header == null) + if (page.Header == null) throw new InvalidOperationException ("Using TreeView.HoverNodeStyle requires Page.Header to be non-null (e.g. )."); RegisterStyle (HoverNodeStyle, HoverNodeLinkStyle); script.AppendFormat (_OnPreRender_Script_HoverStyle, @@ -1159,7 +1161,7 @@ namespace System.Web.UI.WebControls ClientScriptManager.GetScriptLiteral (HoverNodeLinkStyle.RegisteredCssClass)); } - Page.ClientScript.RegisterStartupScript (typeof(TreeView), this.UniqueID, script.ToString (), true); + page.ClientScript.RegisterStartupScript (typeof(TreeView), this.UniqueID, script.ToString (), true); script = null; } } diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/ValidationSummary.cs b/mcs/class/System.Web/System.Web.UI.WebControls/ValidationSummary.cs index 10d084495f7..7b86d1347a6 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/ValidationSummary.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/ValidationSummary.cs @@ -242,7 +242,7 @@ namespace System.Web.UI.WebControls { #endif override void Render(HtmlTextWriter writer) { #if NET_2_0 - if (!Enabled) + if (!IsEnabled) return; #endif ValidatorCollection validators; diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/WebControl.cs b/mcs/class/System.Web/System.Web.UI.WebControls/WebControl.cs index 0ea00fac0a5..fc6f2b8782d 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/WebControl.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/WebControl.cs @@ -408,9 +408,12 @@ namespace System.Web.UI.WebControls { } #if NET_2_0 - protected internal bool IsEnabled + protected +#endif + internal bool IsEnabled { get { +#if NET_2_0 WebControl wc = this; while (wc != null) { if (!wc.Enabled) @@ -418,10 +421,11 @@ namespace System.Web.UI.WebControls { wc = wc.Parent as WebControl; } return true; +#else + return Enabled; +#endif } } -#endif - public void ApplyStyle (Style s) { @@ -519,7 +523,7 @@ namespace System.Web.UI.WebControls { if (AccessKey != string.Empty) writer.AddAttribute (HtmlTextWriterAttribute.Accesskey, AccessKey); - if (!enabled) + if (!IsEnabled) writer.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled", false); if (ToolTip != string.Empty) diff --git a/mcs/class/System.Web/System.Web_standalone_test.dll.sources b/mcs/class/System.Web/System.Web_standalone_test.dll.sources index 8cf81919931..94df3345885 100644 --- a/mcs/class/System.Web/System.Web_standalone_test.dll.sources +++ b/mcs/class/System.Web/System.Web_standalone_test.dll.sources @@ -13,3 +13,4 @@ Test/standalone-tests/PageMetaAttributes.cs Test/standalone-tests/FormViewUpdateParameters_Bug607722.cs Test/standalone-tests/RootBuilderChildControlTypes_Bug603541.cs Test/standalone-tests/MD5PasswordAuth_Bug601727.cs +Test/standalone-tests/WebControlsMustUseIsEnabled_Bug571715.cs diff --git a/mcs/class/System.Web/Test/standalone-tests/WebControlsMustUseIsEnabled_Bug571715.cs b/mcs/class/System.Web/Test/standalone-tests/WebControlsMustUseIsEnabled_Bug571715.cs new file mode 100644 index 00000000000..7aac35d687e --- /dev/null +++ b/mcs/class/System.Web/Test/standalone-tests/WebControlsMustUseIsEnabled_Bug571715.cs @@ -0,0 +1,65 @@ +// +// Authors: +// Marek Habersack (mhabersack@novell.com) +// +// (C) 2010 Novell, Inc http://novell.com/ +// + +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +using System; +using System.Collections.Generic; +using System.IO; +using System.Web; +using System.Web.Hosting; + +using StandAloneRunnerSupport; +using StandAloneTests; + +using NUnit.Framework; + +namespace StandAloneTests.WebControlsMustUseIsEnabled_Bug571715 +{ + [TestCase ("WebControlsMustUseIsEnabled_Bug571715", "WebControl descendants must use IsEnabled instead of Enabled (Bug #571715)")] + public sealed class Test_01 : ITestCase + { + public string PhysicalPath { + get { return Path.Combine (Consts.BasePhysicalDir, "WebControlsMustUseIsEnabled_Bug571715"); } + } + + public string VirtualPath { + get { return "/"; } + } + + public bool SetUp (List runItems) + { + runItems.Add (new TestRunItem ("default.aspx", Default_Aspx)); + + return true; + } + + void Default_Aspx (string result, TestRunItem runItem) + { + string originalHtml = "
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
IDFULLNAME 
1Sheryl Hunter
2Dean Straight
3Marjorie Green
\r\n
"; + Helpers.ExtractAndCompareCodeFromHtml (result, originalHtml, "#A1"); + } + } +} diff --git a/mcs/class/System.Web/Test/standalone/WebControlsMustUseIsEnabled_Bug571715/People.xml b/mcs/class/System.Web/Test/standalone/WebControlsMustUseIsEnabled_Bug571715/People.xml new file mode 100644 index 00000000000..5033f39ae19 --- /dev/null +++ b/mcs/class/System.Web/Test/standalone/WebControlsMustUseIsEnabled_Bug571715/People.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/mcs/class/System.Web/Test/standalone/WebControlsMustUseIsEnabled_Bug571715/default.aspx b/mcs/class/System.Web/Test/standalone/WebControlsMustUseIsEnabled_Bug571715/default.aspx new file mode 100644 index 00000000000..8a8e2b39c84 --- /dev/null +++ b/mcs/class/System.Web/Test/standalone/WebControlsMustUseIsEnabled_Bug571715/default.aspx @@ -0,0 +1,29 @@ +<%@ Page Language="C#" %> + + + + + Bug #571715 + + +
+ <%= AppDomain.CurrentDomain.GetData ("BEGIN_CODE_MARKER") %> + + + + + + + + + <%= AppDomain.CurrentDomain.GetData ("END_CODE_MARKER") %> + +
+ + diff --git a/mcs/class/System.Web/Test/standalone/WebControlsMustUseIsEnabled_Bug571715/web.config b/mcs/class/System.Web/Test/standalone/WebControlsMustUseIsEnabled_Bug571715/web.config new file mode 100644 index 00000000000..7f3d96b2bed --- /dev/null +++ b/mcs/class/System.Web/Test/standalone/WebControlsMustUseIsEnabled_Bug571715/web.config @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.25.1