title: Rendering user controls in EPIserver dynamic content
body: <p>Im trying to make a EPIserver dynamic content control, the content i want is a user control which i already made(a slider), every thing seems to work just fine until i insert the dynamic content control onto the page/area i want to use it.</p>
  
  <p>When i now go to the page i have created it displays the "static" content:</p>
  
  <pre><code>&lt;h3&gt;Dynamic slider&lt;/h3&gt;
  &lt;TextBox runat="server" ID="txtTest" /&gt;
  &lt;cd:TopSlider runat="server" ID="MySlider"/&gt;
  </code></pre>
  
  <p>out of these 3 items the header and the textbox is shown, but not the "cd:TopSlider",
  and in the OnPageLoad i set the text in the TextBox to 'FooBar' but this is not displayed either, it seams it never goes server-side, I've tried to place breakpoints but non is triggered . . .</p>
  
  <p>Here is the code for the DynamicContent files:</p>
  
  <p><em>The usercontrol which is loaded DynamicContentTest.ascx.cs:</em></p>
  
  <pre><code>public partial class DynamicContentTest : System.Web.UI.UserControl
      {
          public IEnumerable&lt;SliderPage&gt; DataSource { get; set; }
  
          protected override void OnLoad(EventArgs e)
          {
              base.OnLoad(e);
              txtTest.Text = "FooBar";
  
              MySlider.DataSource = DataSource;
              MySlider.DataBind();
  
          }
      }
  </code></pre>
  
  <p><em>DynamicContentTest.ascx:</em></p>
  
  <pre><code>&lt;%@ Register TagPrefix="cd" TagName="TopSlider" Src="~/UserControls/TopSlider.ascx" %&gt;
  &lt;!-- Slider --&gt;
  &lt;h3&gt;Dynamic slider&lt;/h3&gt;
  &lt;asp:TextBox runat="server" ID="txtTest" /&gt;
  &lt;cd:TopSlider runat="server" ID="mySlider"/&gt;
  &lt;!-- END Slider --&gt;
  </code></pre>
  
  <p><em>DynamicContentControl:</em></p>
  
  <pre><code>[DynamicContentPlugIn(
          DisplayName = "Dynamic slider",
          Description = "Displays a slider",
          ViewUrl = "~/UserControls/DynamicContent/Custom/DynamicContentTest.ascx")]
      public class DynamicSliderControl : UserControlBase
      {
          public PageReference SlidesRoot { get; set; }
  
          public System.Web.UI.Control GetControl(EPiServer.PageBase hostPage)
          {
              var userControl = (UserControls.DynamicContent.Custom.DynamicContentTest)hostPage.LoadControl("~/UserControls/DynamicContent/Custom/DynamicContentTest.ascx");
              userControl.DataSource = SlidesRoot != null ?
                  SlidesRoot.GetChildrenOfType&lt;SliderPage&gt;() : null;
              return userControl;
          }
  
          public bool RendersWithControl
          {
              get { return true; }
          }
  
          public string State { get; set; }
      }
  </code></pre>
  
  <p>I used these articles as guide's:</p>
  
  <p><a href="http://tedgustaf.com/en/blog/2010/10/user-control-for-specifying-dynamic-content-settings-in-episerver/" rel="nofollow">Create EPiServer dynamic content with advanced settings</a></p>
  
  <p><a href="http://tedgustaf.com/en/blog/2011/4/creating-dynamic-content-in-episerver-cms-6-r2/" rel="nofollow">Creating simple Dynamic Content in EPiServer CMS 6 R2</a></p>