diff options
12 files changed, 133 insertions, 71 deletions
diff --git a/mcs/class/System.Web/System.Web.UI.HtmlControls/ChangeLog b/mcs/class/System.Web/System.Web.UI.HtmlControls/ChangeLog index d3b874f85b3..cd1d09bd6ba 100644 --- a/mcs/class/System.Web/System.Web.UI.HtmlControls/ChangeLog +++ b/mcs/class/System.Web/System.Web.UI.HtmlControls/ChangeLog @@ -1,3 +1,23 @@ +2002-07-17 Gonzalo Paniagua Javier <gonzalo@ximian.com> + + * HtmlAnchor.cs: + * HtmlButton.cs: + * HtmlInputButton.cs: + * HtmlInputCheckBox.cs: + * HtmlInputHidden.cs: + * HtmlInputImage.cs: + * HtmlInputText.cs: + * HtmlTextArea.cs: Initialize EventHandlerList indexer. + + * HtmlContainerControl.cs: almost rewritten to use a LiteralControl + instead of maintaining some flags and strings. Implemented + LoadViewState. + + * HtmlControl.cs: fixed constructor and added ViewStateIgnoreCase. + + * HtmlSelect.cs: fixed TrackViewState, SaveViewState, SelectedIndices + and Value. + 2002-07-12 Gonzalo Paniagua Javier <gonzalo@ximian.com> * HtmlGenericControl.cs: fixed TagName signature and get/set. diff --git a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlAnchor.cs b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlAnchor.cs index 7b210c297aa..67a2b7f76f9 100644 --- a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlAnchor.cs +++ b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlAnchor.cs @@ -13,7 +13,7 @@ namespace System.Web.UI.HtmlControls{ [DefaultEvent("ServerClick")]
public class HtmlAnchor : HtmlContainerControl, IPostBackEventHandler{
- private static readonly object EventServerClick;
+ private static readonly object EventServerClick = new object ();
static HtmlAnchor(){
EventServerClick = new Object();
diff --git a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlButton.cs b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlButton.cs index 266f5a873b5..4b507d6d4c4 100644 --- a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlButton.cs +++ b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlButton.cs @@ -13,7 +13,7 @@ namespace System.Web.UI.HtmlControls{ [DefaultEvent("ServerClick")]
public class HtmlButton : HtmlContainerControl, IPostBackEventHandler{
- private static readonly object EventServerClick;
+ private static readonly object EventServerClick = new object ();
//Checked
static HtmlButton(){
diff --git a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlContainerControl.cs b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlContainerControl.cs index c257ec85a0b..b7f4aac2108 100644 --- a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlContainerControl.cs +++ b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlContainerControl.cs @@ -1,13 +1,16 @@ // // System.Web.UI.HtmlControls.HtmlContainerControl.cs // -// Author -// Bob Smith <bob@thestuff.net> +// Authors: +// Bob Smith <bob@thestuff.net> +// Gonzalo Paniagua Javier (gonzalo@ximian.com) // // (C) Bob Smith +// (c) 2002 Ximian, Inc. (http://www.ximian.com) // using System; +using System.Text; using System.Web; using System.Web.UI; @@ -33,45 +36,55 @@ namespace System.Web.UI.HtmlControls { public abstract class HtmlContainerControl : HtmlControl{ - private string _innerHtml = String.Empty; - private string _innerText = String.Empty; - private bool _doText = false; - private bool _doChildren = true; + public HtmlContainerControl () : this ("span") {} - public HtmlContainerControl() : base(){} - - public HtmlContainerControl(string tag) : base(tag) {} + public HtmlContainerControl (string tag) : base(tag) {} public virtual string InnerHtml { - get { return _innerHtml; } + get { + if (Controls.Count == 0) + return String.Empty; + + bool is_literal = true; + StringBuilder text = new StringBuilder (); + foreach (Control ctrl in Controls) { + LiteralControl lc = ctrl as LiteralControl; + if (lc == null) { + is_literal = false; + break; + } + text.Append (lc.Text); + } + + if (!is_literal) + throw new HttpException ("There is no literal content!"); + + return text.ToString (); + } + set { - _innerHtml = value; - _doText = false; - _doChildren = false; + Controls.Clear (); + Controls.Add (new LiteralControl (value)); + ViewState ["innerhtml"] = value; } } public virtual string InnerText { - get { return _innerText; } + get { + return InnerHtml; //FIXME: decode it + } + set { - _innerText = value; - _doText = true; - _doChildren = false; + InnerHtml = value; //FIXME: encode it } } - protected override void Render(HtmlTextWriter writer) + protected override void Render (HtmlTextWriter writer) { - base.Render (writer); - if (_doChildren) - RenderChildren(writer); - else if (_doText) - writer.Write (HttpUtility.HtmlEncode (_innerText)); - else - writer.Write (_innerHtml); - + RenderBeginTag (writer); + RenderChildren (writer); RenderEndTag (writer); } @@ -80,10 +93,25 @@ namespace System.Web.UI.HtmlControls writer.WriteEndTag (TagName); } + protected override void RenderAttributes (HtmlTextWriter writer) + { + ViewState.Remove ("innerhtml"); + base.RenderAttributes (writer); + } + protected override ControlCollection CreateControlCollection () { return new ControlCollection (this); } + protected override void LoadViewState (object savedState) + { + if (savedState != null) { + base.LoadViewState (savedState); + string inner = ViewState ["innerhtml"] as string; + if (inner != null) + InnerHtml = inner; + } + } } } diff --git a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlControl.cs b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlControl.cs index 3a830dc3d48..50621e48f15 100644 --- a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlControl.cs +++ b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlControl.cs @@ -22,11 +22,11 @@ namespace System.Web.UI.HtmlControls{ private AttributeCollection _attributes = new AttributeCollection(new StateBag(true));
private bool _disabled = false;
- public HtmlControl(){}
+ public HtmlControl() : this ("span") {}
public HtmlControl(string tag)
{
- if(tag != null && tag != String.Empty) _tagName = tag;
+ _tagName = tag;
}
protected override ControlCollection CreateControlCollection ()
@@ -107,5 +107,12 @@ namespace System.Web.UI.HtmlControls{ {
get { return _tagName; }
}
+
+ protected override bool ViewStateIgnoresCase
+ {
+ get {
+ return true;
+ }
+ }
}
}
diff --git a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputButton.cs b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputButton.cs index 75e6688670e..342e1575a76 100755 --- a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputButton.cs +++ b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputButton.cs @@ -14,7 +14,7 @@ namespace System.Web.UI.HtmlControls{ [DefaultEvent("ServerClick")]
public class HtmlInputButton : HtmlInputControl, IPostBackEventHandler{
- private static readonly object EventServerClick;
+ private static readonly object EventServerClick = new object ();
public HtmlInputButton(): base ("button")
{
diff --git a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputCheckBox.cs b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputCheckBox.cs index f93e60a6a61..575b312b16e 100755 --- a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputCheckBox.cs +++ b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputCheckBox.cs @@ -15,7 +15,7 @@ namespace System.Web.UI.HtmlControls{ [DefaultEvent("ServerChange")]
public class HtmlInputCheckBox : HtmlInputControl, IPostBackDataHandler{
- private static readonly object EventServerChange;
+ private static readonly object EventServerChange = new object ();
public HtmlInputCheckBox(): base("checkbox"){}
diff --git a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputHidden.cs b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputHidden.cs index 2a3dce63faf..65e4864284d 100755 --- a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputHidden.cs +++ b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputHidden.cs @@ -15,7 +15,7 @@ namespace System.Web.UI.HtmlControls{ [DefaultEvent("ServerChange")]
public class HtmlInputHidden : HtmlInputControl, IPostBackDataHandler{
- private static readonly object EventServerChange;
+ private static readonly object EventServerChange = new object ();
public HtmlInputHidden () : base ("hidden")
{
diff --git a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputImage.cs b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputImage.cs index e0699386f10..62a5e1fb00c 100755 --- a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputImage.cs +++ b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputImage.cs @@ -15,7 +15,7 @@ namespace System.Web.UI.HtmlControls{ [DefaultEvent("ServerClick")]
public class HtmlInputImage : HtmlInputControl, IPostBackEventHandler, IPostBackDataHandler{
- private static readonly object EventServerClick;
+ private static readonly object EventServerClick = new object ();
private int _x, _y;
public HtmlInputImage(): base("image"){}
diff --git a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputText.cs b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputText.cs index 6e6ce48c125..345981371db 100755 --- a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputText.cs +++ b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputText.cs @@ -16,7 +16,7 @@ namespace System.Web.UI.HtmlControls{ [ValidationProperty("Value")]
public class HtmlInputText : HtmlInputControl, IPostBackDataHandler{
- private static readonly object EventServerChange;
+ private static readonly object EventServerChange = new object ();
public HtmlInputText(string type):base(type){}
public HtmlInputText():base("text"){}
diff --git a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlSelect.cs b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlSelect.cs index f146009ed30..0b42de9a6aa 100755 --- a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlSelect.cs +++ b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlSelect.cs @@ -20,7 +20,7 @@ namespace System.Web.UI.HtmlControls{ private int _cachedSelectedIndex;
private object _dataSource;
- private static readonly object EventServerChange;
+ private static readonly object EventServerChange = new object ();
private ListItemCollection _items;
public HtmlSelect():base("select"){
@@ -35,23 +35,25 @@ namespace System.Web.UI.HtmlControls{ throw new HttpException("HtmlSelect cannot have children of Type " + obj.GetType().Name);
}
- protected virtual void ClearSelection(){
- for (int i =0; i<= Items.Count; i++){
- Items[i].Selected = false;
- }
+ protected virtual void ClearSelection()
+ {
+ foreach (ListItem item in Items)
+ item.Selected = false;
}
protected override ControlCollection CreateControlCollection(){
return new EmptyControlCollection(this);
}
- protected override void LoadViewState(object savedState){
- if (savedState != null){
+ protected override void LoadViewState(object savedState)
+ {
+ if (savedState != null) {
Triplet state = (Triplet) savedState;
- LoadViewState(state.First);
- Items.LoadViewState(state.Second);
- object thirdState = state.Third;
- if (thirdState != null) Select((int[]) thirdState);
+ base.LoadViewState (state.First);
+ Items.LoadViewState (state.Second);
+ object indices = state.Third;
+ if (indices != null)
+ Select ((int[]) indices);
}
}
@@ -149,15 +151,18 @@ namespace System.Web.UI.HtmlControls{ writer.Indent = writer.Indent - 1;
}
- protected override object SaveViewState(){
- object itemsViewState = SaveViewState();
- object third = null;
- if (Events[EventServerChange] != null && !Disabled && Visible){
- third = SelectedIndices;
- }
- if (third != null && base.SaveViewState() != null && itemsViewState != null){
- return new Triplet(itemsViewState, base.SaveViewState(), third);
- }
+ protected override object SaveViewState ()
+ {
+ object baseViewState = base.SaveViewState ();
+ object itemsViewState = Items.SaveViewState ();
+ object indices = null;
+
+ if (Events[EventServerChange] != null || !Disabled || Visible)
+ indices = SelectedIndices;
+
+ if (indices != null || baseViewState != null || itemsViewState != null)
+ return new Triplet (baseViewState, itemsViewState, indices);
+
return null;
}
@@ -176,8 +181,8 @@ namespace System.Web.UI.HtmlControls{ NameValueCollection postCollection)
{
//get the posted selectedIndices[]
- string[] postedValueColl = postCollection.GetValues(postDataKey);
- bool valid = false;
+ string [] postedValueColl = postCollection.GetValues(postDataKey);
+ bool changed = false;
if (postedValueColl != null){
if (!Multiple){
//single selection
@@ -186,7 +191,7 @@ namespace System.Web.UI.HtmlControls{ if (postedValue != SelectedIndex){
//set the SelectedIndex
SelectedIndex = postedValue;
- valid = true;
+ changed = true;
}
}
else{
@@ -200,19 +205,19 @@ namespace System.Web.UI.HtmlControls{ if( postedValueCount == SelectedIndices.Length)
for (int i = 0; i <= postedValueCount; i++)
if(arr[i] == SelectedIndices[i])
- valid = true;
+ changed = true;
else
- valid = true;
+ changed = true;
//commit the posted Values
- if(valid)
+ if(changed)
Select(arr);
}
}
else if (SelectedIndex != -1){
SelectedIndex = -1;
- valid = true;
+ changed = true;
}
- return valid;
+ return changed;
}
void IPostBackDataHandler.RaisePostDataChangedEvent ()
@@ -222,7 +227,7 @@ namespace System.Web.UI.HtmlControls{ //starts tracking changes to the viewstate
protected override void TrackViewState(){
- TrackViewState();
+ base.TrackViewState();
Items.TrackViewState();
}
@@ -351,8 +356,10 @@ namespace System.Web.UI.HtmlControls{ _cachedSelectedIndex = value;
return;
}
- else if (value < -1 || value >= Items.Count)
+
+ if (value < -1 || value >= Items.Count)
throw new ArgumentOutOfRangeException();
+
ClearSelection();
if (value >= 0)
Items[value].Selected = true;
@@ -363,15 +370,15 @@ namespace System.Web.UI.HtmlControls{ get{
int[] indices = new int[3];
int indicesCount = 0;
- for(int i=0; i <= Items.Count; i++){
- if(Items[i].Selected){
+ for(int i=0; i < Items.Count; i++){
+ if (Items[i].Selected){
if( indicesCount == (int) indices.Length){
int[] temp = new int[indicesCount + indicesCount];
indices.CopyTo(temp,0);
indices = temp;
}
- indicesCount++;
indices[indicesCount] = i;
+ indicesCount++;
}
}
int[] arr = new int[indicesCount];
@@ -393,10 +400,10 @@ namespace System.Web.UI.HtmlControls{ }
}
- public string Value{
+ public string Value {
get{
int selectedIndex = SelectedIndex;
- if (selectedIndex >=0 && selectedIndex <= Items.Count){
+ if (selectedIndex >=0 && selectedIndex < Items.Count){
return Items[selectedIndex].Value;
}
return String.Empty;
diff --git a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlTextArea.cs b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlTextArea.cs index 0f0775d1aba..d38e81aaa00 100644 --- a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlTextArea.cs +++ b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlTextArea.cs @@ -15,7 +15,7 @@ namespace System.Web.UI.HtmlControls{ [DefaultEvent("ServerChange")]
public class HtmlTextArea : HtmlContainerControl, IPostBackDataHandler{
- private static readonly object EventServerChange;
+ private static readonly object EventServerChange = new object ();
public HtmlTextArea(): base("textarea"){}
|