Last post Dec 13, 2007 03:33 AM by ZXie
Dec 10, 2007 04:17 AM|ZXie|LINK
if you cache two usercontrols in a page, and both of which contains either a menu or treeview(or any control that injects embeded css style into parent page), then the first time you get the response right, but on second request or any later request where
the cached content is used, the outout will not be correct. inspecting the html source, I found some inline style definition is missing for the later response. It seems this is a bug in asp.net: BasePartialCachingControl.PreRenderRecursiveInternal(), where
only the last cached style output is used, and any previous style string set by other cached usercontrols positioned earlier in the page is overwritten.
Besides the senerio of two side by side usercontrols being cached, there is another senerio, suppose one usercontrol uses embedded style(both menu and treeview use these, and many other ajax controls also use this technique to inject style definition into
the html head element), and it contains a child usercontrol who is also set to cached, and also uses embedded style, the two controls expiration event will ussually not coincident, and now suppose that the parent one is being regenerated while the child one
has still a valid cached version, in this case, since the child one's css settings will go through the path of page.header.StyleSheet.CSSStyleString (in BasePartialCachingControl.PreRenderRecursiveInternal), so it will not be merged with the parent control's
css setting, which results an incorrect css setting string being stored into cache, so any subsequence output of the parent usercontrol from cache will be incorrect.
I once wondered if this had been fixed in latest service pack, so downloaded .net framework 2.0 service pack 1, unfortunately, it was not.
I hope someone can verify the above, and if verified a bug, hope Microsoft can fix this bug.
Dec 13, 2007 03:33 AM|ZXie|LINK
a suggested fix for it:
in basepartial, add a childrenCssRawstring property
in basepartial.GetCssStyleRenderString(), append childrenCssRawstring to the final output
change RegisterCssStyleString to:
internal void StyleSheetInternal.RegisterCssStyleString(string outputString)
((StyleSheetInternal) this.StyleSheet).CSSStyleString +="\r\n"+ outputString;
Page page = this._owner.Page;
if (page.PartialCachingControlStack != null)
foreach (BasePartialCachingControl control in page.PartialCachingControlStack)