Strongly Typed Controls and DynamicControl/Dynamic Field

2 posts, 0 answers
  1. David
    David avatar
    41 posts
    Member since:
    Aug 2014

    Posted 01 Feb 2016 Link to this post

    Using Entity Framework, Models, DataAnnotation and ASP WebForms, you can leverage the asp 'DynamicControl' and 'DynamicField' controls, which refer back to the model declaration and reflect the proper formatting and validation rules without having to duplicate those values in the markup or code behind.


    The article,, goes into detail on how to get this to work with the basic ASP gridview and dataform controls.


    Attempting to apply this technique to the RadDataForm, a control that can be strongly typed, results in the error: "The DynamicControl/DynamicField needs to exist inside a data control that is bound to a data source that supports Dynamic Data."

    Huh? The RadDataForm doesn't support Dynamic Data?

    Google search is frustrating due to the search returns dominated by the topic of "Dynamic Control" instead of "DynamicControl", and searched on this forum came up empty.

    How can I place a DynamicControl into the EditItemTemplate of a RadDataForm and benefit from the formatting and other annotations listed on the Model?


  2. Konstantin Dikov
    Konstantin Dikov avatar
    2466 posts

    Posted 04 Feb 2016 Link to this post

    Hi David,

    Although that we have resolved the issue in the support ticket that you have opened, I will post the answer here as well:

    "Please note that (as with any other data bound control), you need to call the EnableDynamicData method within the Page's Init or Load events for the control with the correct model type:
    <telerik:RadAjaxPanel runat="server">
        <telerik:RadGrid runat="server" ID="RadGrid1" DataSourceID="LinqDataSource1" AllowPaging="true">
            <MasterTableView AutoGenerateColumns="false">
                            <asp:DynamicControl ID="DynamicControl1" DataField="ID" runat="server" />
                            <asp:DynamicControl ID="DynamicControl1" Mode="Edit" DataField="ID" runat="server" />
        <telerik:RadDataForm runat="server" ID="RadDataForm1"></telerik:RadDataForm>

    And the code-behind:
    protected void Page_Init(object sender, EventArgs e)

    And the model:
    public class ItemsCollection
        public ItemsCollection()
        public List<CustomType> AllItems
                List<CustomType> _availableGenres = new List<CustomType>();
                for (int i = 0; i < 500; i++)
                    _availableGenres.Add(new CustomType(i, "value" + i));
                return _availableGenres;
    public class CustomType
        [Required(ErrorMessage = "Last name is required.")]
        [Range(0, 5)]
        public int ID { get; set; }
        public string Value { get; set; }
        public CustomType()
        public CustomType(int id, string value)
            this.ID = id;
            this.Value = value;

    Konstantin Dikov
    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 Feedback Portal and vote to affect the priority of the items
Back to Top