Last post Jan 31, 2011 03:45 AM by sagar11188
Aug 20, 2010 06:33 AM|iGulfam|LINK
Often we need ASP .Net calendar control in our webpages. Most of the times we require navigation in between dates of the calendar control but there can be a requirement that when we want that users should not be able to select dates from month other than
the current month.
Some people might be thinking in mind that Microsoft has provided theShowNextPrevMonth property of a calendar control which can be set to false in order to disable the navigation in between months.
Ok, this will disable navigation but what about the dates of adjacent months shown in current month?
Following is the output of a normal Calendar control when ShowNextPrevMonth is not set to false.
Note the red circles in above image. July and September will allow you to navigate through other months and red circles below will allow you to select dates of adjacent months.
Ok now we set the ShowNextPrevMonth property to false and see the output. Following is the output in this case.
So setting out the ShowNextPrevMonth property has disabled the July and Septemberlinks but dates of adjacent months are still there which can be selected as well. How to disable/hide these? Unfortunately there is no such default property
provided using which one can disable or hide these dates but fortunately doing this using code is not a complex task. Use following code and this will hide these dates of adjacent months. We will make use ofDayRender event of the Calendar control.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Calendar1.ShowNextPrevMonth = False
Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs) Handles Calendar1.DayRender
If e.Day.IsOtherMonth Then
e.Cell.Text = ""
Following is the output of above code
You see there are no navigational links (July, September) and also dates of adjacent months have been hidden.
Hope this will solve your issue.
For more detail view you can follow the following link
other month dates
Aug 30, 2010 12:09 AM|riswadkarharshad|LINK
Thanks a lot for your post. I am using calendar control in one of my project which had the same requirement but I was not able to work on it.
By referring to your post and link provided, I can do the needful :)
Jan 20, 2011 02:21 AM|sreejithk2000|LINK
A related post: http://forums.asp.net/t/1440237.aspx
Jan 31, 2011 03:45 AM|sagar11188|LINK
Thanks for the code.Currently I needed that.
Thanks for the trick. :)