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

Forums / Developing with Sitefinity / Null reference in Control Designer

Null reference in Control Designer

2 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    25 Sep 2010
    Link to this post
    Hi,

    I've followed (in fact ive copied and pasted) Gabe's tutorial on Control Designers at: http://www.sitefinitywatch.com/blog/09-02-20/Making_Control_Editing_User-Friendly_with_Sitefinity_Control_Designers.aspx

    Problem is, even copied and pasted the code fails, at the following point:

    /// <summary>
        /// Executed automatically when the I'm done button is clicked in the Control Designer.
        /// </summary>
        public override void OnSaving()
        {
            // Set the underlying control properties to the new values.
            ((CustomControlBase) DesignedControl).Text = TextBox1.Text;
            ((CustomControlBase) DesignedControl).Priority =
                (CustomControlBase.PriorityType) Enum.Parse(typeof(CustomControlBase.PriorityType), DropDownList1.SelectedValue);
        }

    DropDownList1.SelectedValue is always empty and therefore the enum.parse throws an exception.

    I know the OnSaving method can get access to DropDownList1 because otherwise the following method would have thrown an error.

    protected virtual DropDownList DropDownList1 {
        get { return base.Container.GetControl<DropDownList>("DropDownList1", true); }
    }

    Strangely, if i switch to the Advanced tab and select the dropdown from that list there is no error.

    Any help would be aprpeciated.

    Thanks
    higgsy
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    26 Sep 2010
    Link to this post
    Hi Alastair,

    DropDownList1.SelectedValue is not valid string inside OnSaving and when you call  Enum.Parse Method and an  error is thrown. Try removing if (!Page.IsPostBack) during initialization

    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
2 posts, 0 answered