Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > WebPartInfoProvider.GetVirtualWebpartUrl View modes: 
User avatar
Member
Member
bvg-omni - 11/16/2011 3:35:54 PM
   
WebPartInfoProvider.GetVirtualWebpartUrl
I have no problem retrieving the url of the virtual web part, but when I attempt to render the HTML of the control by using:

string virtualWebPartUrl = WebPartInfoProvider.GetVirtualWebpartUrl(string, string, string);
Control control = Page.LoadControl(virtualWebPartUrl);
StringBuilder sb = new StringBuilder();
StringWriter tw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(tw);
control.RenderControl(hw);
string html = sb.ToString();

It renders the html perfectly, but it does not render the html based on the properties I selected for the web part in the CMS Desk.

For instance, I'm using a CSS Menu web part control and I set the Path="./%" so I only want the menu to show items within it's own document, but the Html renders the control with a Path = "/%", so it is bringing back all of the documents in the node tree.

What is the best way to render the web part?
Thank you.

User avatar
Member
Member
kentico_michal - 11/16/2011 10:11:25 PM
   
RE:WebPartInfoProvider.GetVirtualWebpartUrl
Hello,

Please take a look at following code snippet that shows how to dynamically render the CMSRepeater control:


Page pageHolder = new Page();

CMSRepeater rep = (CMSRepeater)pageHolder.LoadControl(typeof(CMSRepeater), null);

// set properties
rep.ClassNames = "cms.article";
rep.Path = "/%";
rep.TransformationName = "cms.article.default";

pageHolder.Controls.Add(rep);

StringWriter output = new StringWriter();
HttpContext.Current.Server.Execute(pageHolder, output, false);

string html =output.ToString();


Best regards,
Michal Legen

User avatar
Member
Member
bvg-omni - 11/29/2011 11:01:33 AM
   
RE:WebPartInfoProvider.GetVirtualWebpartUrl
I am not talking about any specific web part control such as Menu or Repeater. I do not want to manually set the properties, they are already set int he CMSDesk. I am trying to render the exact web part control with all the properties of such control inside a specific zone set inside the CMSDesk.

If I add a CMSMenu control web part to "zoneCenter" of my page and I want to get the virtual web part url...

string virtualWebPartUrl = WebPartInfoProvider.GetVirtualWebpartUrl("/menu1", "zoneCenter", "cmsmenulist_menu1");

shouldn't the virtualWebPartUrl render the webpart with the properties that were set inside the CMSDesk?

We are trying to render the html output of select web parts inside zones of document pages, but just the web part html, and the control renders correctly except that the properties that we set inside the CMSDesk are not set after running the virutualWebPartUrl.

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 12/5/2011 9:46:24 AM
   
RE:WebPartInfoProvider.GetVirtualWebpartUrl
Please look closely at the code that Michal has provided you. Note this line:



HttpContext.Current.Server.Execute(pageHolder, output, false);


When a control has any databound content or any output that depends on context (the properties from CMSDesk), session, etc. you must add the control to a Page object and Execute it to get the correct output.