More in this section

Forums / Developing with Sitefinity / LoadDefaultMetaField - Null reference exception

LoadDefaultMetaField - Null reference exception

2 posts, 0 answered
  1. Viktor
    Viktor avatar
    22 posts
    01 Nov 2011
    18 Nov 2011
    Link to this post

    I'm writing my custom control and my code fails when it attempts to retrieve a default meta field.

    public Telerik.Sitefinity.Metadata.Model.IMetaField MetaField
    if(this._metaField == null)
    this._metaField = this.LoadDefaultMetaField();
    this._metaField.FieldName = "NamedTextBox_" + this.ClientID;
    return this._metaField;
    set { this._metaField = value; }

    One of the problems is that I didn't find a clear explanation in SDK or on the blogs on how we should be using MetaFields. I guess that it will persist value from my custom field into the database, but that's only a guess.

    Can you please give a brief explanation on how we should be using meta fields and why this.LoadDefaultMetaField throws a null reference exception?

    Thank you
  2. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    18 Sep 2017
    23 Nov 2011
    Link to this post
    Hi Viktor,

    Yes you are right LoadDefaultMetafield will persist the value of the form control into the database using database mapping attribute. I suppose you are getting an exception because of a missing using . I suggest adding using Telerik.Sitefinity.Model, using Telerik.Sitefinity.Modules.Forms.Web.UI.Fields. I suppose you have already added this as described here. If you are still getting the exception can you paste some code here to see the code used?

    Stanislav Velikov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested 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