ASP.NET Calendar: Hide PrevMonthText or NextMonthText

If you use the ASP.NET Calendar Control and want to hide the PrevMonthText or NextMonthText then you need to use the PreRender-Event from the Calendar-Control.

In this example I hide the PrevMonthText (Hyperlink) when the current year and month equals calendars visible year and month. Note: You must set/init the VisibileDate-Property in Page_Load-Event. In my example I want that the start month and year of the control is set to today.

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
MyCalendarControl.VisibleDate = DateTime.Now;
}
}

protected void MyCalendarControl_PreRender(object sender, EventArgs e)
{
// hide previous month link in calendar when current month and year equals calendars month and year
MyCalendarControl.PrevMonthText = DateTime.Now.Month == EventsCalendar.VisibleDate.Month && DateTime.Now.Year == EventsCalendar.VisibleDate.Year ? string.Empty : "<"
}