Try Now
More in this section

Forums / Developing with Sitefinity / Inserting User Controls into markup - Best Practices

Inserting User Controls into markup - Best Practices

2 posts, 0 answered
  1. Jeremy
    Jeremy avatar
    17 posts
    28 Jul 2010
    17 Nov 2010
    Link to this post
    I need to grab some data from my DB, then insert it into some markup. For example:

    <div id="container">
      <div id="content">
        <p>Some Text</p>
        <p>DYNAMIC DATA</p>
        <p>Some more text</p>

    My first idea was to create a User Control that grabs the data and then just displayed it in a <asp:Label /> or <asp:Literal>. Since I can't insert a User Control in a Generic Content module, I was going to surround my User Control with two Generic Content modules. The first would include my markup up to and including the <p> for the DYNAMIC DATA. The second would start at the </p> for the DYNAMIC DATA and then finish out the page.

    I figured it wouldn't look right in the admin, but everything should come together when the page is rendered live. However, the first Generic Content module sees my missing closing tags and automatically fills them in.

    Is there a way to tell the Generic Content module not to fix broken markup?

    Or, is there a better way to integrate data driven content in the middle of my markup?

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    19 Oct 2016
    17 Nov 2010
    Link to this post
    Hello Jeremy,

    You can map the external template for Generic Content control - GenericContentDesigner.ascx and remove ConvertToXhtml filter.

    Another option is creating a custom control that does not uses GenericContent and fetches data from your database.

    Kind 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