From: Argiris K. <be...@us...> - 2005-11-26 12:14:55
|
Update of /cvsroot/magicajax/magicajax/Core/UI/Controls In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26744/Core/UI/Controls Modified Files: AjaxPanel.cs Log Message: Fixed a serious flaw of the AjaxPanel mechanism. Now only children that are webcontrols are enclosed inside an additional span tag. Literal content and HtmlControls are rendered together. Index: AjaxPanel.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/UI/Controls/AjaxPanel.cs,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** AjaxPanel.cs 25 Nov 2005 20:45:47 -0000 1.23 --- AjaxPanel.cs 26 Nov 2005 12:14:41 -0000 1.24 *************** *** 265,277 **** protected override void AddedControl(Control control, int index) { ! if ( IsPageNoStoreMode ) { ! // If the ID of the added control is null, find a unique id manually, ! // or else the default naming order may cause mismatches. ! if (control.ID == null || control.ID == String.Empty) ! control.ID = FindUniqueID(); } - _addedControls.Add (control); base.AddedControl (control, index); } --- 265,281 ---- protected override void AddedControl(Control control, int index) { ! if ( control is WebControl ) { ! if ( IsPageNoStoreMode ) ! { ! // If the ID of the added control is null, find a unique id manually, ! // or else the default naming order may cause mismatches. ! if (control.ID == null || control.ID == String.Empty) ! control.ID = FindUniqueID(); ! } ! ! _addedControls.Add (control); } base.AddedControl (control, index); } *************** *** 286,293 **** protected override void RemovedControl(Control control) { ! if (_addedControls.Contains(control)) ! _addedControls.Remove (control); ! else ! _removedControls.Add (control); base.RemovedControl (control); --- 290,300 ---- protected override void RemovedControl(Control control) { ! if ( control is WebControl ) ! { ! if (_addedControls.Contains(control)) ! _addedControls.Remove (control); ! else ! _removedControls.Add (control); ! } base.RemovedControl (control); *************** *** 311,333 **** HtmlTextWriter litewriter = new HtmlTextWriter(new System.IO.StringWriter(sb)); for (int i=0; i < Controls.Count; i++) { Control con = Controls[i]; ! writer.WriteBeginTag ("span"); ! writer.WriteAttribute ("id", GetAjaxElemID(con)); ! writer.Write (HtmlTextWriter.TagRightChar); ExtendedRenderControl (con, fullwriter, litewriter); writer.Write (sbFull.ToString()); ! _controlHtmlFingerprints[con] = Util.GetFingerprint(sb.ToString()); sbFull.Length = 0; sb.Length = 0; - - writer.WriteEndTag ("span"); } _addedControls.Clear(); _removedControls.Clear(); --- 318,365 ---- HtmlTextWriter litewriter = new HtmlTextWriter(new System.IO.StringWriter(sb)); + StringBuilder sbLiteral = new StringBuilder(); + HtmlTextWriter literalwriter = new HtmlTextWriter(new System.IO.StringWriter(sbLiteral)); + for (int i=0; i < Controls.Count; i++) { Control con = Controls[i]; ! // Put inside span tag only WebControls ! bool isWebControl = ( con is WebControl ); ! ! if ( isWebControl ) ! { ! writer.WriteBeginTag ("span"); ! writer.WriteAttribute ("id", GetAjaxElemID(con)); ! writer.WriteAttribute ("name", "__ajaxmark"); ! writer.Write (HtmlTextWriter.TagRightChar); ! ! literalwriter.WriteBeginTag ("span"); ! literalwriter.WriteAttribute ("id", GetAjaxElemID(con)); ! literalwriter.WriteAttribute ("name", "__ajaxmark"); ! literalwriter.Write (HtmlTextWriter.TagRightChar); ! } ExtendedRenderControl (con, fullwriter, litewriter); writer.Write (sbFull.ToString()); + string html = sb.ToString(); ! if ( isWebControl ) ! { ! _controlHtmlFingerprints[con] = Util.GetFingerprint(html); ! writer.WriteEndTag ("span"); ! literalwriter.WriteEndTag ("span"); ! } ! else ! { ! literalwriter.Write (html); ! } sbFull.Length = 0; sb.Length = 0; } + _controlState.LiteralFingerprint = Util.GetFingerprint(sbLiteral.ToString()); + _addedControls.Clear(); _removedControls.Clear(); *************** *** 438,441 **** --- 470,476 ---- HtmlTextWriter fullwriter = new HtmlTextWriter(new System.IO.StringWriter(sbFull)); + StringBuilder sbLiteral = new StringBuilder(); + HtmlTextWriter literalwriter = new HtmlTextWriter(new System.IO.StringWriter(sbLiteral)); + // To be used in 'NoStore' mode to continue the rendering of control tree. HtmlTextWriter nullWriter = new HtmlTextWriter(System.IO.TextWriter.Null); *************** *** 451,462 **** Control con = Controls[i]; ! fullwriter.WriteBeginTag ("span"); ! fullwriter.WriteAttribute ("id", GetAjaxElemID(con)); ! fullwriter.Write (HtmlTextWriter.TagRightChar); ExtendedRenderControl (con, fullwriter, litewriter, true); - fullwriter.WriteEndTag ("span"); - _controlHtmlFingerprints[con] = Util.GetFingerprint(sb.ToString()); sb.Length = 0; } --- 486,519 ---- Control con = Controls[i]; ! // Put inside span tag only WebControls ! bool isWebControl = ( con is WebControl ); ! ! if ( isWebControl ) ! { ! fullwriter.WriteBeginTag ("span"); ! fullwriter.WriteAttribute ("id", GetAjaxElemID(con)); ! fullwriter.WriteAttribute ("name", "__ajaxmark"); ! fullwriter.Write (HtmlTextWriter.TagRightChar); ! ! literalwriter.WriteBeginTag ("span"); ! literalwriter.WriteAttribute ("id", GetAjaxElemID(con)); ! literalwriter.WriteAttribute ("name", "__ajaxmark"); ! literalwriter.Write (HtmlTextWriter.TagRightChar); ! } ExtendedRenderControl (con, fullwriter, litewriter, true); + string html = sb.ToString(); + + if ( isWebControl ) + { + fullwriter.WriteEndTag ("span"); + literalwriter.WriteEndTag ("span"); + _controlHtmlFingerprints[con] = Util.GetFingerprint(html); + } + else + { + literalwriter.Write (html); + } sb.Length = 0; } *************** *** 467,477 **** AjaxCallHelper.WriteSetHtmlOfElementScript (html, ClientID); } } else { foreach (Control con in _removedControls) { _controlHtmlFingerprints.Remove(con); - AjaxCallHelper.WriteRemoveElementScript (ClientID, GetAjaxElemID(ClientID + "_" + con.ClientID)); } --- 524,539 ---- AjaxCallHelper.WriteSetHtmlOfElementScript (html, ClientID); } + + _controlState.LiteralFingerprint = Util.GetFingerprint(sbLiteral.ToString()); } else { + // Increase script writing level because we want literal content to + // be rendered before the child controls renderings + AjaxCallHelper.IncreaseWritingLevel(); + foreach (Control con in _removedControls) { _controlHtmlFingerprints.Remove(con); } *************** *** 480,487 **** Control con = Controls[i]; string html; sbFull.Length = sb.Length = 0; ! if (_addedControls.Contains(con)) { // It's a new control, create it on the client at the appropriate place. --- 542,561 ---- Control con = Controls[i]; + // Only WebControls are inside a span tag + bool isWebControl = ( con is WebControl ); + + if ( isWebControl ) + { + literalwriter.WriteBeginTag ("span"); + literalwriter.WriteAttribute ("id", GetAjaxElemID(con)); + literalwriter.WriteAttribute ("name", "__ajaxmark"); + literalwriter.Write (HtmlTextWriter.TagRightChar); + literalwriter.WriteEndTag ("span"); + } + string html; sbFull.Length = sb.Length = 0; ! if ( isWebControl && _addedControls.Contains(con) ) { // It's a new control, create it on the client at the appropriate place. *************** *** 489,493 **** html = sbFull.ToString(); ! AjaxCallHelper.WriteAddElementScript (ClientID, "span", GetAjaxElemID(con), html, GetNextExistingElement(i)); _controlHtmlFingerprints[con] = Util.GetFingerprint(sb.ToString()); --- 563,567 ---- html = sbFull.ToString(); ! AjaxCallHelper.WriteSetHtmlOfElementScript (html, GetAjaxElemID(con)); _controlHtmlFingerprints[con] = Util.GetFingerprint(sb.ToString()); *************** *** 507,517 **** html = sb.ToString(); - string htmlFingerprint = Util.GetFingerprint(html); ! // If it's html rendering fingerprint is the same, ignore it. ! if (htmlFingerprint != (string)_controlHtmlFingerprints[con]) { ! ExtendedWriteSetHtmlOfElementScript(html, GetAjaxElemID(con)); ! _controlHtmlFingerprints[con] = htmlFingerprint; } --- 581,599 ---- html = sb.ToString(); ! if ( isWebControl ) { ! string htmlFingerprint = Util.GetFingerprint(html); ! ! // If it's html rendering fingerprint is the same, ignore it. ! if (htmlFingerprint != (string)_controlHtmlFingerprints[con]) ! { ! ExtendedWriteSetHtmlOfElementScript(html, GetAjaxElemID(con)); ! _controlHtmlFingerprints[con] = htmlFingerprint; ! } ! } ! else ! { ! literalwriter.Write (html); } *************** *** 522,525 **** --- 604,619 ---- } } + + AjaxCallHelper.DecreaseWritingLevel(); + + string literalhtml = sbLiteral.ToString(); + string literalFingerprint = Util.GetFingerprint(literalhtml); + if ( _controlState.LiteralFingerprint != literalFingerprint ) + { + ExtendedWriteSetHtmlOfElementScript (literalhtml, this.ClientID); + _controlState.LiteralFingerprint = Util.GetFingerprint(literalhtml); + } + + AjaxCallHelper.MergeUpperWritingLevelsWithCurrent(); } *************** *** 602,606 **** /// <summary> /// It's part of the ExtendedRenderControl(Control control) method. It replaces the html rendering ! /// of a RenderedByScriptControl with a Span tag named "__ajax_rbs". /// </summary> /// <param name="sender"></param> --- 696,700 ---- /// <summary> /// It's part of the ExtendedRenderControl(Control control) method. It replaces the html rendering ! /// of a RenderedByScriptControl with a Span tag named "__ajaxmark". /// </summary> /// <param name="sender"></param> *************** *** 609,613 **** { RenderedByScriptControl con = (RenderedByScriptControl) sender; ! e.Writer.Write ("<span id=\"{0}$rbs\" name=\"__ajax_rbs\"></span>", con.ClientID); e.AbortRendering = true; } --- 703,707 ---- { RenderedByScriptControl con = (RenderedByScriptControl) sender; ! e.Writer.Write ("<span id=\"{0}$rbs\" name=\"__ajaxmark\"></span>", con.ClientID); e.AbortRendering = true; } *************** *** 831,834 **** --- 925,929 ---- private class ControlCollectionState { + private string _literalFingerprint; private SortedList _controlHtmlFingerprints; private Control _owner; *************** *** 847,853 **** /// </summary> /// <param name="controlHtmlFingerprints"></param> ! public ControlCollectionState(SortedList controlHtmlFingerprints, Control owner) { _owner = owner; _controlHtmlFingerprints = controlHtmlFingerprints; } --- 942,949 ---- /// </summary> /// <param name="controlHtmlFingerprints"></param> ! public ControlCollectionState(string literalFingerprint, SortedList controlHtmlFingerprints, Control owner) { _owner = owner; + _literalFingerprint = literalFingerprint; _controlHtmlFingerprints = controlHtmlFingerprints; } *************** *** 865,872 **** { SortedList controlHtmlFingerprints = new SortedList(); if (panelControlFingerprints != String.Empty) { string[] namevaluepairs = panelControlFingerprints.Split(';'); ! for (int i = 0; i < namevaluepairs.Length; i++) { string namevaluepair = namevaluepairs[i]; --- 961,979 ---- { SortedList controlHtmlFingerprints = new SortedList(); + string literalFingerprint = null; + if (panelControlFingerprints != String.Empty) { string[] namevaluepairs = panelControlFingerprints.Split(';'); ! if (MagicAjaxContext.Current.Configuration.CompareMode == MagicAjax.Configuration.OutputCompareMode.FullHtml) ! { ! literalFingerprint = UnicodeEncoding.Default.GetString(Convert.FromBase64String(namevaluepairs[0])); ! } ! else ! { ! literalFingerprint = namevaluepairs[0]; ! } ! ! for (int i = 1; i < namevaluepairs.Length; i++) { string namevaluepair = namevaluepairs[i]; *************** *** 884,888 **** } ! return new ControlCollectionState(controlHtmlFingerprints, owner); } else --- 991,995 ---- } ! return new ControlCollectionState(literalFingerprint, controlHtmlFingerprints, owner); } else *************** *** 902,905 **** --- 1009,1018 ---- } + public string LiteralFingerprint + { + get { return _literalFingerprint; } + set { _literalFingerprint = value; } + } + public System.Collections.SortedList ControlHtmlFingerprints { *************** *** 924,933 **** System.Text.StringBuilder sbuilder = new System.Text.StringBuilder(); foreach (string key in _controlHtmlFingerprints.Keys) { ! if (_controlHtmlFingerprints.IndexOfKey(key) > 0) ! { ! sbuilder.Append(';'); ! } string keyWithoutNamingcontainer = key.Substring(panelClientID.Length + 1); --- 1037,1053 ---- System.Text.StringBuilder sbuilder = new System.Text.StringBuilder(); + // Put the literal content first, before the control/fingerprint pairs + if (MagicAjaxContext.Current.Configuration.CompareMode == MagicAjax.Configuration.OutputCompareMode.FullHtml) + { + sbuilder.Append (Convert.ToBase64String(UnicodeEncoding.Default.GetBytes(LiteralFingerprint))); + } + else + { + sbuilder.Append (LiteralFingerprint); + } + foreach (string key in _controlHtmlFingerprints.Keys) { ! sbuilder.Append(';'); string keyWithoutNamingcontainer = key.Substring(panelClientID.Length + 1); *************** *** 987,991 **** { RenderedByScriptControl con = (RenderedByScriptControl) sender; ! Write ("<span id=\"{0}$rbs\" name=\"__ajax_rbs\">", con.ClientID); onlyFullRender = true; } --- 1107,1111 ---- { RenderedByScriptControl con = (RenderedByScriptControl) sender; ! Write ("<span id=\"{0}$rbs\" name=\"__ajaxmark\">", con.ClientID); onlyFullRender = true; } |