More in this section

Forums / Developing with Sitefinity / Programmatically retrieve widget settings.

Programmatically retrieve widget settings.

5 posts, 2 answered
  1. Erik
    Erik avatar
    62 posts
    Registered:
    02 May 2011
    02 Apr 2012
    Link to this post
    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!
  2. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    02 Apr 2012
    Link to this post
    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!
    Answered
  3. Erik
    Erik avatar
    62 posts
    Registered:
    02 May 2011
    02 Apr 2012
    Link to this post
    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?
  4. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    02 Apr 2012
    Link to this post
    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.

    Answered
  5. Erik
    Erik avatar
    62 posts
    Registered:
    02 May 2011
    02 Apr 2012
    Link to this post
    Sorry, I read the article wrong. I found it now, thanks!
5 posts, 2 answered