X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Web%2FSystem.Web.UI.WebControls%2FListBox.cs;h=5018cadc97f775d907c05ab380748bff88269828;hb=a01fb8227b364663dbc0a8ef50cebf8e6b9563d0;hp=5d11015c2bc716b65c68d4c0128ac7e2f3849c78;hpb=881f83658281916d8f0784df7c726ecb7cc289db;p=mono.git 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 5d11015c2bc..5018cadc97f 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/ListBox.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/ListBox.cs @@ -32,6 +32,7 @@ using System.Drawing; using System.Globalization; using System.Collections.Specialized; using System.Security.Permissions; +using System.Web.Util; namespace System.Web.UI.WebControls { @@ -40,9 +41,7 @@ namespace System.Web.UI.WebControls { [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] // attributes [ValidationProperty("SelectedItem")] -#if NET_2_0 [SupportsEventValidation] -#endif public class ListBox : ListControl, IPostBackDataHandler { public ListBox () @@ -50,7 +49,7 @@ namespace System.Web.UI.WebControls { } [Browsable(false)] -#if NET_2_0 && HAVE_CONTROL_ADAPTERS +#if HAVE_CONTROL_ADAPTERS public virtual new #else public override @@ -61,7 +60,7 @@ namespace System.Web.UI.WebControls { } [Browsable(false)] -#if NET_2_0 && HAVE_CONTROL_ADAPTERS +#if HAVE_CONTROL_ADAPTERS public virtual new #else public override @@ -72,7 +71,7 @@ namespace System.Web.UI.WebControls { } [Browsable(false)] -#if NET_2_0 && HAVE_CONTROL_ADAPTERS +#if HAVE_CONTROL_ADAPTERS public virtual new #else public override @@ -82,9 +81,6 @@ namespace System.Web.UI.WebControls { set { base.BorderWidth = value; } } -#if ONLY_1_1 - [Bindable(true)] -#endif [DefaultValue(4)] [WebSysDescription ("")] [WebCategory ("Appearance")] @@ -114,58 +110,40 @@ namespace System.Web.UI.WebControls { } } -#if ONLY_1_1 - [Bindable(false)] - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToolTip { - get { return String.Empty; } - set { /* Tooltip is always String.Empty */ } - } -#endif -#if NET_2_0 public virtual int[] GetSelectedIndices () { return (int []) GetSelectedIndicesInternal ().ToArray (typeof (int)); } -#endif protected override void AddAttributesToRender (HtmlTextWriter writer) { if (Page != null) Page.VerifyRenderingInServerForm (this); - base.AddAttributesToRender (writer); -#if NET_2_0 if (ID != null) writer.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID); -#else - writer.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID); -#endif - - if (AutoPostBack) -#if NET_2_0 - writer.AddAttribute (HtmlTextWriterAttribute.Onchange, Page.ClientScript.GetPostBackEventReference (GetPostBackOptions (), true)); -#else - writer.AddAttribute (HtmlTextWriterAttribute.Onchange, - Page.ClientScript.GetPostBackClientHyperlink (this, "")); -#endif + if (AutoPostBack) { + string onchange = Page.ClientScript.GetPostBackEventReference (GetPostBackOptions (), true); + onchange = String.Concat ("setTimeout('", onchange.Replace ("\\", "\\\\").Replace ("'", "\\'"), "', 0)"); + writer.AddAttribute (HtmlTextWriterAttribute.Onchange, BuildScriptAttribute ("onchange", onchange)); + } + if (SelectionMode == ListSelectionMode.Multiple) writer.AddAttribute (HtmlTextWriterAttribute.Multiple, - "multiple"); + "multiple", false); writer.AddAttribute (HtmlTextWriterAttribute.Size, - Rows.ToString (CultureInfo.InvariantCulture)); + Rows.ToString (Helpers.InvariantCulture)); + + base.AddAttributesToRender (writer); } -#if NET_2_0 PostBackOptions GetPostBackOptions () { PostBackOptions options = new PostBackOptions (this); options.ActionUrl = null; options.ValidationGroup = null; - options.Argument = ""; + options.Argument = String.Empty; options.RequiresJavaScriptProtocol = false; options.ClientSubmit = true; options.PerformValidation = CausesValidation && Page != null && Page.AreValidatorsUplevel (ValidationGroup); @@ -174,60 +152,28 @@ namespace System.Web.UI.WebControls { return options; } -#endif - -#if NET_2_0 - protected internal -#else - protected -#endif - override void RenderContents (HtmlTextWriter writer) - { -#if NET_2_0 - bool havePage = Page != null; -#endif - foreach (ListItem item in Items) { -#if NET_2_0 - if (havePage) - Page.ClientScript.RegisterForEventValidation (this.UniqueID, item.Value.ToString ()); -#endif - writer.WriteBeginTag ("option"); - if (item.Selected) { - writer.WriteAttribute ("selected", "selected", false); - } - writer.WriteAttribute ("value", item.Value, true); - writer.Write (">"); - string encoded = HttpUtility.HtmlEncode (item.Text); - writer.Write (encoded); - writer.WriteEndTag ("option"); - writer.WriteLine (); - } - } -#if NET_2_0 protected internal -#else - protected -#endif 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 protected virtual -#endif bool LoadPostData (string postDataKey, NameValueCollection postCollection) { + EnsureDataBound (); string [] values = postCollection.GetValues (postDataKey); if (values == null || values.Length == 0) { int prev_index = SelectedIndex; SelectedIndex = -1; return (prev_index != -1); } + ValidateEvent (UniqueID, values [0]); if (SelectionMode == ListSelectionMode.Single) return SelectSingle (values); @@ -270,15 +216,11 @@ namespace System.Web.UI.WebControls { return false; } -#if NET_2_0 protected virtual -#endif void RaisePostDataChangedEvent () { -#if NET_2_0 if (CausesValidation) Page.Validate (ValidationGroup); -#endif OnSelectedIndexChanged (EventArgs.Empty); } @@ -292,7 +234,12 @@ namespace System.Web.UI.WebControls { { RaisePostDataChangedEvent (); } + internal override bool MultiSelectOk () + { + return this.SelectionMode == ListSelectionMode.Multiple; + } } } +