+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Trouble reading page controls

Trouble reading page controls

4 posts, 0 answered
  1. Lupi
    Lupi avatar
    38 posts
    Registered:
    17 May 2004
    30 Aug 2010
    Link to this post
    Hello,

    I have troubles reading some of the controls in a ICmsPage. I have the following code:

    ICmsPage page = <valid_page>;
    foreach (ICmsWebControl control in page.Controls)
    {
        string controlType = control.ControlType.ToString();
        if (controlType == "Telerik.News.WebControls.NewsView")
        {
            NewsView newsView = control.LoadControl() as NewsView;
        }
    }


    The line with "LoadControl()" throws a runtime exception - NullPointerException. At the same time I am able to load other controls like Telerik.Cms.Engine.WebControls.GenericContent or Telerik.Libraries.DownloadList. Any idea what might be cause this exception.

    Also another issue - using the same principle I load a Telerik.Cms.Web.UI.DynamicHyperLink control:

    Telerik.Cms.Web.UI.DynamicHyperLink dynamicHyperLink = control.LoadControl() as Telerik.Cms.Web.UI.DynamicHyperLink;

    Then if I try to access the property dynamicHyperLink.NavigateUrl I get again NullPointerException. At the same time I am able to read the .Target and .Text properties.

    Best regards,
    Lupi
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    30 Aug 2010
    Link to this post
    Hi Lupi,

    1. Use Staged version of the page

    2. Use typeof when you are looking for the control

    IList<Telerik.Cms.ICmsWebControl> pageControls = currentPage.Staged.Controls;
      foreach (Telerik.Cms.ICmsWebControl webCtrl in pageControls)
      {
     
          if (webCtrl.ControlType == typeof(Telerik.News.WebControls.NewsView))
          {
              var newsControl = webCtrl.LoadControl() as NewsView;
          }
     
          if (webCtrl.ControlType == typeof(Telerik.Cms.Engine.WebControls.DynamicHyperLink))
          {
              var dhl = webCtrl.LoadControl() as Telerik.Cms.Engine.WebControls.DynamicHyperLink;
              dhl.NavigateUrl = "http://www.google.com";
          }
     
      }


    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Lupi
    Lupi avatar
    38 posts
    Registered:
    17 May 2004
    11 Sep 2010
    Link to this post
    Hello,

    Thanks for the advice but unfortunately this didn't solve the problem. I'm still getting the NullReferenceException when trying to load, say a NewsView. Here are some exception details:

    System.NullReferenceException
        {"Object reference not set to an instance of an object."}
     
    Data:
        {System.Collections.ListDictionaryInternal}
     
    Source:
        Telerik.Cms.Engine
     
    Stack trace:
       at Telerik.Cms.Engine.Design.SettingsListConverter.DeserializeDesignerSettings(String settingsCollection)
       at Telerik.Cms.Engine.Design.SettingsListConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
       at System.ComponentModel.TypeConverter.ConvertFromInvariantString(String text)
       at Telerik.Cms.Data.WebControlBase.LoadControl(Control control, PropertyDescriptorCollection properties)
       at Telerik.Cms.Data.WebControlBase.LoadControl(TemplateControl template, Control& control)
       at Telerik.Cms.Data.WebControlBase.LoadControl(TemplateControl template)
       ...

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    12 Sep 2010
    Link to this post
    Hi Lupi,

    The class SettingsListConverter  implements methods for converting list of BaseSetting objects to string and vice versa. Make sure that you do not pass an invalid format for Master and Details settings of NewsView control located on the page. Try adding a new control on a page. We are not able to reproduce these issues locally and it is hard to tell you why you receive a null exception.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
4 posts, 0 answered