Adding an Event on Specific Date in Calendar control

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:
  1. <asp:Calendar ID="Calendar1" runat="server">                       
  2.    </asp:Calendar>                               
Add Day Render Event:
  1. protected void Page_Load(object sender, EventArgs e)  
  2.  {  
  3.      Calendar1.DayRender += new DayRenderEventHandler(Calendar1_DayRender);  
  4.  }  
  5.   
  6.  void Calendar1_DayRender(object sender, DayRenderEventArgs e)  
  7.  {  
  8.      if (e.Day.Date.Day == 8)  
  9.      {  
  10.          e.Cell.Controls.Add(new LiteralControl("<br/>Holiday"));  
  11.      }  
  12.  }  
Output:

 
Ebook Download
View all
Learn
View all