views:

415

answers:

2

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.

A: 

After researching this it appears that the DayRender Event occurs too late in the page lifecycle to add controls with events. This is why my init method is not firing and updating the literal controls text value.

Looks like I may need to write a simple class and override the ToString() method to write out the necessary HTML.

keeney
A: 

See my answer to a similar question. I found a way, but its not pretty.

rick schott