From: Dion O. <dol...@us...> - 2005-11-15 00:31:07
|
Update of /cvsroot/magicajax/magicajax/Core/UI/Controls In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7835/magicajax/Core/UI/Controls Modified Files: AjaxPanel.cs Log Message: Added an alternative panelcontrolstate storage (in hidden form element, instead of Session). To test it, compile with CLIENTSIDE_PANELSTATE (compilation symbol) Index: AjaxPanel.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/UI/Controls/AjaxPanel.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AjaxPanel.cs 14 Nov 2005 18:50:43 -0000 1.2 --- AjaxPanel.cs 15 Nov 2005 00:30:54 -0000 1.3 *************** *** 27,30 **** --- 27,31 ---- using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; + using System.Globalization; namespace MagicAjax.UI.Controls *************** *** 81,85 **** --- 82,90 ---- private ArrayList _addedControls = new ArrayList(); private ArrayList _removedControls = new ArrayList(); + #if CLIENTSIDE_PANELSTATE + private Hashtable _controlHtmlHashes = new Hashtable(); + #else private Hashtable _controlHtmls = new Hashtable(); + #endif private NoVerifyRenderingPage _noVerifyPage = new NoVerifyRenderingPage(); private ControlCollectionState _controlState = new ControlCollectionState(); *************** *** 182,187 **** ExtendedRenderControl (control, litewriter); ! _controlHtmls[control] = sb.ToString(); sb.Length = 0; } --- 187,196 ---- ExtendedRenderControl (control, litewriter); ! ! #if CLIENTSIDE_PANELSTATE ! _controlHtmlHashes[control] = sb.ToString().GetHashCode(); ! #else _controlHtmls[control] = sb.ToString(); + #endif sb.Length = 0; } *************** *** 201,205 **** --- 210,218 ---- _addedControls.Clear(); _removedControls.Clear(); + #if CLIENTSIDE_PANELSTATE + _controlHtmlHashes.Clear(); + #else _controlHtmls.Clear(); + #endif } #endregion *************** *** 290,294 **** --- 303,311 ---- ExtendedRenderControl (con, fullwriter, litewriter); writer.Write (sbFull.ToString()); + #if CLIENTSIDE_PANELSTATE + _controlHtmlHashes[con] = sb.ToString().GetHashCode(); + #else _controlHtmls[con] = sb.ToString(); + #endif sbFull.Length = 0; sb.Length = 0; *************** *** 310,315 **** protected virtual void SaveControlState() { _controlState.SetControlIDs (_controlHtmls); ! _controlState.Save (this.UniqueID); } --- 327,336 ---- protected virtual void SaveControlState() { + #if CLIENTSIDE_PANELSTATE + _controlState.SetControlIDs(_controlHtmlHashes); + #else _controlState.SetControlIDs (_controlHtmls); ! #endif ! _controlState.Save (this.UniqueID, this.Page); } *************** *** 326,335 **** --- 347,364 ---- // Find new and previous controls _addedControls.Clear(); + #if CLIENTSIDE_PANELSTATE + _controlHtmlHashes.Clear(); + #else _controlHtmls.Clear(); + #endif foreach (Control con in this.Controls) { if ( _controlState.ControlIDHtmls.ContainsKey(con.ClientID) ) { + #if CLIENTSIDE_PANELSTATE + _controlHtmlHashes[con] = _controlState.ControlIDHtmls[con.ClientID]; + #else _controlHtmls[con] = _controlState.ControlIDHtmls[con.ClientID]; + #endif } else *************** *** 403,408 **** fullwriter.WriteEndTag ("span"); ! _controlHtmls[con] = sb.ToString(); sb.Length = 0; } --- 432,440 ---- fullwriter.WriteEndTag ("span"); ! #if CLIENTSIDE_PANELSTATE ! _controlHtmlHashes[con] = sb.ToString().GetHashCode(); ! #else _controlHtmls[con] = sb.ToString(); + #endif sb.Length = 0; } *************** *** 419,423 **** --- 451,459 ---- foreach (Control con in _removedControls) { + #if CLIENTSIDE_PANELSTATE + _controlHtmlHashes.Remove(con); + #else _controlHtmls.Remove (con); + #endif AjaxCallHelper.WriteRemoveElementScript (ClientID, GetAjaxElemID(con)); } *************** *** 438,443 **** AjaxCallHelper.WriteAddElementScript (ClientID, "span", GetAjaxElemID(con), html, GetNextExistingElement(i)); output.Write (html); ! _controlHtmls[con] = sb.ToString(); } else --- 474,482 ---- AjaxCallHelper.WriteAddElementScript (ClientID, "span", GetAjaxElemID(con), html, GetNextExistingElement(i)); output.Write (html); ! #if CLIENTSIDE_PANELSTATE ! _controlHtmlHashes[con] = sb.ToString().GetHashCode(); ! #else _controlHtmls[con] = sb.ToString(); + #endif } else *************** *** 445,449 **** ExtendedRenderControl (con, output, litewriter); html = sb.ToString(); ! // If it's html rendering is the same, ignore it. if (html != (string)_controlHtmls[con]) --- 484,496 ---- ExtendedRenderControl (con, output, litewriter); html = sb.ToString(); ! #if CLIENTSIDE_PANELSTATE ! int htmlHashCode = html.GetHashCode(); ! // If it's html rendering hash is the same, ignore it. ! if (htmlHashCode != (int)_controlHtmlHashes[con]) ! { ! ExtendedWriteSetHtmlOfElementScript(html, GetAjaxElemID(con)); ! _controlHtmlHashes[con] = htmlHashCode; ! } ! #else // If it's html rendering is the same, ignore it. if (html != (string)_controlHtmls[con]) *************** *** 452,455 **** --- 499,503 ---- _controlHtmls[con] = html; } + #endif } } *************** *** 707,712 **** --- 755,765 ---- { Control con = Controls[i]; + #if CLIENTSIDE_PANELSTATE + if (!_addedControls.Contains(con) && _controlHtmlHashes[con] != null) + return GetAjaxElemID(con); + #else if (!_addedControls.Contains(con) && _controlHtmls[con] != null) return GetAjaxElemID(con); + #endif } *************** *** 731,741 **** #region Private Class ControlCollectionState [Serializable] ! private class ControlCollectionState { private Hashtable _controlIDHtmls; public static ControlCollectionState LoadState(string panelUniqueID) { return (ControlCollectionState) HttpContext.Current.Session[GetPageKey(panelUniqueID)]; } --- 784,827 ---- #region Private Class ControlCollectionState [Serializable] ! private class ControlCollectionState { + #if CLIENTSIDE_PANELSTATE + private SortedList _controlIDHtmlHashes; + + public ControlCollectionState(SortedList controlIDHtmlHashes) + { + _controlIDHtmlHashes = controlIDHtmlHashes; + } + #else private Hashtable _controlIDHtmls; + #endif public static ControlCollectionState LoadState(string panelUniqueID) { + #if CLIENTSIDE_PANELSTATE + string panelKey = "__PANELCONTROLSTATE_" + panelUniqueID; + string panelControlStates = HttpContext.Current.Request.Form[panelKey]; + if (panelControlStates != null) + { + SortedList controlIDHtmlHashes = new SortedList(); + string[] namevaluepairs = panelControlStates.Split(';'); + for (int i = 0; i < namevaluepairs.Length; i++) + { + string namevaluepair = namevaluepairs[i]; + string[] namevalue = namevaluepair.Split('#'); + controlIDHtmlHashes.Add(string.Format("{0}_{1}", panelUniqueID, namevalue[0]), int.Parse(namevalue[1], CultureInfo.InvariantCulture)); + } + + return new ControlCollectionState(controlIDHtmlHashes); + + //return new ControlCollectionState((Hashtable)AjaxCallHelper.DeserializeFromString(panelControlStates)); + } + else + { + return null; + } + #else return (ControlCollectionState) HttpContext.Current.Session[GetPageKey(panelUniqueID)]; + #endif } *************** *** 745,768 **** } public Hashtable ControlIDHtmls { get { return _controlIDHtmls; } } public void SetControlIDs (Hashtable controlHtmls) { _controlIDHtmls.Clear(); foreach (Control con in controlHtmls.Keys) _controlIDHtmls.Add (con.ClientID, (string)controlHtmls[con]); } ! public void Save(string panelUniqueID) { HttpContext.Current.Session[GetPageKey(panelUniqueID)] = this; } public ControlCollectionState() { _controlIDHtmls = new Hashtable(); } } --- 831,892 ---- } + #if CLIENTSIDE_PANELSTATE + public System.Collections.SortedList ControlIDHtmls + { + get { return _controlIDHtmlHashes; } + } + #else public Hashtable ControlIDHtmls { get { return _controlIDHtmls; } } + #endif public void SetControlIDs (Hashtable controlHtmls) { + #if CLIENTSIDE_PANELSTATE + _controlIDHtmlHashes.Clear(); + foreach (Control con in controlHtmls.Keys) + _controlIDHtmlHashes.Add(con.ClientID, (int)controlHtmls[con]); + #else _controlIDHtmls.Clear(); foreach (Control con in controlHtmls.Keys) _controlIDHtmls.Add (con.ClientID, (string)controlHtmls[con]); + #endif } ! public void Save(string panelUniqueID, Page page) { + #if CLIENTSIDE_PANELSTATE + System.Text.StringBuilder serializedContolStates = new System.Text.StringBuilder(); + + foreach (string key in _controlIDHtmlHashes.Keys) + { + if (_controlIDHtmlHashes.IndexOfKey(key) > 0) + { + serializedContolStates.Append(';'); + } + + string keyWithoutNamingcontainer = key.Substring(panelUniqueID.Length + 1); + + serializedContolStates.AppendFormat("{0}#{1}", keyWithoutNamingcontainer, ((int)_controlIDHtmlHashes[key]).ToString(CultureInfo.InvariantCulture)); + } + + page.RegisterHiddenField("__PANELCONTROLSTATE_" + panelUniqueID, + serializedContolStates.ToString()); + HttpContext.Current.Items.Add("__PANELCONTROLSTATE_" + panelUniqueID, + serializedContolStates.ToString()); + #else HttpContext.Current.Session[GetPageKey(panelUniqueID)] = this; + #endif } public ControlCollectionState() { + #if CLIENTSIDE_PANELSTATE + _controlIDHtmlHashes = new SortedList(); + #else _controlIDHtmls = new Hashtable(); + #endif } } |