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.
eg.
protected void Cal1_DayRender(object sender, DayRenderEventArgs e)
{
foreach (var item in MyDataSet.Where(s=>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 );
}
}
}
The UserControl contains a property called DisplayText which set the value the text value of a literal control in the OnInit method.
Any ideas??
Thanks in advance.