DayRender event is raised while the Calendar control is being rendered, you cannot add a control that can also raise an event, such as LinkButton. You can only add static controls, such as System.Web.UI.LiteralControl, Label, Image, and HyperLink.
Add Calendar Control on to the page:Calendar.aspx:
- <asp:Calendar ID="Calendar1" runat="server">
- </asp:Calendar>
Add Day Render Event:
- protected void Page_Load(object sender, EventArgs e)
- {
- Calendar1.DayRender += new DayRenderEventHandler(Calendar1_DayRender);
- }
-
- void Calendar1_DayRender(object sender, DayRenderEventArgs e)
- {
- if (e.Day.Date.Day == 8)
- {
- e.Cell.Controls.Add(new LiteralControl("<br/>Holiday"));
- }
- }
Output: