Home » Programming / Coding

Show/Hide Next Previous Links on Calendar Control – ASP .NET

13 March 2009 1,781 views No Comment

ASP .Net Calendar control is a great tool for showing event calendars etc. If you want to show or hide the next/previous links you can set the NextMonthText and PrevMonthText property. Here is an example of how to do that.

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

protected void Calendar_PreRender(object sender, EventArgs e)
{
// we will show next 3 months from now in this example
DateTime dtMin = DateTime.Now;
DateTime dtMax = DateTime.Now.AddMonths(2);

Response.Write(“<div class=white>aaaaaaaaaaaaaaaa” + dtMin.CompareTo(calendar.VisibleDate) + “</div>”);
if (calendar.VisibleDate.Year == dtMax.Year && calendar.VisibleDate.Month == dtMax.Month)
{
calendar.NextMonthText = string.Empty;
}
else
{
calendar.NextMonthText = “>”;
}

if (calendar.VisibleDate.Year == dtMin.Year && calendar.VisibleDate.Month==dtMin.Month)
{
calendar.PrevMonthText = string.Empty;
}
else
{
calendar.PrevMonthText = “<”;
}
}

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.