Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Using TreeNode.GetValue to get WebPart property View modes: 
User avatar
Certified Developer 10
Certified Developer 10
s.bell-earthlink - 2/7/2011 6:27:27 PM
   
Using TreeNode.GetValue to get WebPart property
Hi,

I am quite new to kentico to please bear with me.

I have a page called resources. On the page is a widget. On the widget is a webpart. The webpart has properties.

I want to use the API to access the webpart properties (from the code behind of a webpart on a different page). I assume that I start by doing this:

TreeNode ResourceNode = TreeHelper.SelectSingleNode("/my-foundation/plan-basics/resources/resources");

This gets me the page, right? Then to get one of the properties I would do this:

string MyValue = ResourceNode.GetValue("MyProperty").ToString();

...except that the property is a member of the webpart rather than the page and so this does not work. What is the correct way to do this?

Thank you!
Steve


User avatar
Kentico Support
Kentico Support
kentico_radekm - 3/9/2011 9:36:01 AM
   
RE:Using TreeNode.GetValue to get WebPart property
Hello.

You can get property of any web part in any page template in code-behind using this code:


// Get proper PageTemplateInfo object
CMS.PortalEngine.PageTemplateInfo iPageTemp = null;
iPageTemp = CMS.PortalEngine.PageTemplateInfoProvider.GetPageTemplateInfo("pageTemplateName");

// Get web part instance
CMS.PortalEngine.WebPartInstance iWebPart = iWebPart = iPageTemp.GetWebPart("properCodeName");

// return required value
string iProperty = (string)iWebPart.GetValue("propertyName");


Best Regards,
Radek Macalik