title: Dynamically adding a UserControl to the DayRender event of the Calendar Control
body: <p>I have a simple UserControl that I'd like to render in each calendar cell. I'd like it render different information based on a data set by passing changing some properties exposed on the UserControl. For some reason this isn't working. I'm wondering if the page cycle is preventing this from working correctly as it seems to work if I load the control on a PageLoad event.</p>
  
  <p>eg. </p>
  
  <pre><code>protected void Cal1_DayRender(object sender, DayRenderEventArgs e)
  {
  
    foreach (var item in MyDataSet.Where(s=&gt;s.AvailibilityDate.Date == e.Day.Date))
              {
  
  //the days match. Render a the usercontrol setting some property values to alter the rendering of the control
  
  MyUserControl userControl = Page.Loadcontrol("~/UserControls/MyUserControl.ascx") as MyUserControl;
  if(userControl != null)
  {
  
  //set the properties
  
  userControl.DisplayText = item.PersonsFullName;
  
     e.Cell.Controls.Add(userControl );
  }
  
  }    
  
  }
  </code></pre>
  
  <p>The UserControl contains a property called DisplayText which set the value the text value of a literal control in the OnInit method.</p>
  
  <p>Any ideas??</p>
  
  <p>Thanks in advance.</p>