Multiple RenderAsHtml() / ctx problem<p></p> <p>Hi,<br>I have a web part which displays multiple lists using<br>SPView.RenderAsHtml() (I need to use the RenderAsHtml rather than adding a<br>ListView control since the list are not coming from the site the webpart is<br>on).<br>The problem I am experiencing is that the links on the item dropdown<br>menu on any of the lists refer to the last list that was added! . For<br>example if the web part shows 3 lists 'a','b' and 'c'  then  clicking &quot;View<br>Item&quot; on the first item  in lists 'a' or 'b' will take me to the first item<br>in list 'c'.<br><br>After some investigation I realised this due to the fact that the links for<br>a list on page are based on a Javascript &quot;contextInfo()&quot; object which is<br>automatically generated for each list. And RenderAsHtml() always calls these<br>ctx1, so each contextInfo object is overwriting the previous one!<br><br>To solve this problem I replaced all references to ctx1 with ctxN, where N<br>is an incremented integer starting at 1000 (to avaoid conflicting with other<br>webparts) see code extract below:</p> <p align=left><br></p> <p dir=ltr style="margin-right:0px" align=left> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div> <p dir=ltr style="margin-right:0px" align=left>SPList list = web.Lists[list name];<br>SPView view = list.DefaultView;<br>lit = new Literal();<br>lit.Text = view.RenderAsHtml();<br>lit.Text =lit.Text.Replace(&quot;ctx1&quot;,string.Format(&quot;ctx{0}&quot;,N.ToString()));<br>lit.Text = lit.Text.Replace(&quot;ctxId = 1&quot;, &quot;ctxId= &quot; +N.ToString());<br>lit.Text = lit.Text.Replace(&quot;CtxNum=\&quot;1\&quot;&quot;, &quot;CtxNum=\&quot;&quot;+ N.ToString() +&quot;\&quot;&quot;);<br>phGrid.Controls.Add(lit);</p> <p dir=ltr style="margin-right:0px" align=left>N++;<br></p> <p align=left> </p></div></div> <p align=left> </p> <p></p> <p dir=ltr style="margin-right:0px" align=left><br><br>This seems to work fine with one problem, for some reason when you hover over the column heading and click the down arrow the filter dropdown menu is no longer displayed.<br><br>If anyone knows how I can solve this, (or how I can tell the webpart server<br>side to create a new javascript contextInfo object for each list I want to<br>render I would appreciate it)<br><br>Thanks,<br><br>Nick<br><br><br></p>© 2009 Microsoft Corporation. All rights reserved.Tue, 22 Jul 2008 19:55:23 Z60fe90a8-850c-4c65-86b9-3d39849da033http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/60fe90a8-850c-4c65-86b9-3d39849da033#60fe90a8-850c-4c65-86b9-3d39849da033http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/60fe90a8-850c-4c65-86b9-3d39849da033#60fe90a8-850c-4c65-86b9-3d39849da033NickyWhttp://social.msdn.microsoft.com/Profile/en-US/?user=NickyWMultiple RenderAsHtml() / ctx problem<p></p> <p>Hi,<br>I have a web part which displays multiple lists using<br>SPView.RenderAsHtml() (I need to use the RenderAsHtml rather than adding a<br>ListView control since the list are not coming from the site the webpart is<br>on).<br>The problem I am experiencing is that the links on the item dropdown<br>menu on any of the lists refer to the last list that was added! . For<br>example if the web part shows 3 lists 'a','b' and 'c'  then  clicking &quot;View<br>Item&quot; on the first item  in lists 'a' or 'b' will take me to the first item<br>in list 'c'.<br><br>After some investigation I realised this due to the fact that the links for<br>a list on page are based on a Javascript &quot;contextInfo()&quot; object which is<br>automatically generated for each list. And RenderAsHtml() always calls these<br>ctx1, so each contextInfo object is overwriting the previous one!<br><br>To solve this problem I replaced all references to ctx1 with ctxN, where N<br>is an incremented integer starting at 1000 (to avaoid conflicting with other<br>webparts) see code extract below:</p> <p align=left><br></p> <p dir=ltr style="margin-right:0px" align=left> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div> <p dir=ltr style="margin-right:0px" align=left>SPList list = web.Lists[list name];<br>SPView view = list.DefaultView;<br>lit = new Literal();<br>lit.Text = view.RenderAsHtml();<br>lit.Text =lit.Text.Replace(&quot;ctx1&quot;,string.Format(&quot;ctx{0}&quot;,N.ToString()));<br>lit.Text = lit.Text.Replace(&quot;ctxId = 1&quot;, &quot;ctxId= &quot; +N.ToString());<br>lit.Text = lit.Text.Replace(&quot;CtxNum=\&quot;1\&quot;&quot;, &quot;CtxNum=\&quot;&quot;+ N.ToString() +&quot;\&quot;&quot;);<br>phGrid.Controls.Add(lit);</p> <p dir=ltr style="margin-right:0px" align=left>N++;<br></p> <p align=left> </p></div></div> <p align=left> </p> <p></p> <p dir=ltr style="margin-right:0px" align=left><br><br>This seems to work fine with one problem, for some reason when you hover over the column heading and click the down arrow the filter dropdown menu is no longer displayed.<br><br>If anyone knows how I can solve this, (or how I can tell the webpart server<br>side to create a new javascript contextInfo object for each list I want to<br>render I would appreciate it)<br><br>Thanks,<br><br>Nick<br><br><br></p>Tue, 04 Mar 2008 14:41:26 Z2008-03-04T14:41:26Z