Programmatically retrieve widget settings.

Posted by Community Admin on 04-Aug-2018 14:07

Programmatically retrieve widget settings.

All Replies

Posted by Community Admin on 02-Apr-2012 00:00

Is there a way to programmatically retrieve settings from a widget on a page? Specifically I want to figure out what the detail template is set to for the Single Item Settings for any given news widget on a page.

Thanks!

Posted by Community Admin on 02-Apr-2012 00:00

Erik,

Runtime settings for widgets on a page are stored in a dictionary property of the PageControl called Properties. However, I believe this dictionary is only populated with properties that are different from the default values.

For an example demonstrating accessing widget properties programmatically, take a look at the Sitefinity Sitemap Module SDK Sample, specifically the SiteMapConfig.cs class which has the following code for locating a NewsView widget and then accessing its properties programmatically.

// retrieve the news view control from the page
var newsView = page.Page.Controls.Where(c => c.ObjectType.StartsWith(typeof(NewsView).FullName)).First();
if (newsView == null) continue;
  
// determine if there is a modified control definition
var controlDefinition = newsView.Properties.Where(p => p.Name == "ControlDefinition").FirstOrDefault();
if (controlDefinition == null)
    // control uses default provider
    providerName = NewsManager.GetDefaultProviderName();
else
    // search for modified provider name in the control
    var providerNameProperty = controlDefinition.ChildProperties.Where(p => p.Name == "ProviderName").FirstOrDefault();
    if (providerNameProperty == null)
        // control is modified, but still uses default provider
        providerName = NewsManager.GetDefaultProviderName();
    else
        // get selected provider name
        providerName = providerNameProperty.Value;

For a list of properties within widget controls that you can access and check for, you can either use the Sitefinity API Reference or the free JustDecompile tool to inspect the widget properties.

I hope this is helpful!

Posted by Community Admin on 02-Apr-2012 00:00

So I looked at the "Sitefinity API Reference" link and I downloaded the SDK but the bat file "Install_Sitefinity API Reference.bat" doesn't exist in it. Is there another way to get this?

Posted by Community Admin on 02-Apr-2012 00:00

Erik, did you run the SDK installer and install the complete package? is there a folder at C:\Program Files (x86)\Telerik\Sitefinity 5.0\SDK\Content\Documents\Chm? this is where the bat file should be.

Posted by Community Admin on 02-Apr-2012 00:00

Sorry, I read the article wrong. I found it now, thanks!

This thread is closed