thoughts on programming and computer related stuff RSS 2.0
# Friday, July 25, 2008
I have been struggling a couple of hours to get the calendar control in .Net to meet my requirements. What I needed was a control to select a date, so a DateTimePicker would be great. This does not exist in the ASP framework, so I needed to use the calendar control or buy some third party tool.

My requirements was that only dates within a given time frame should be clickable. The next and previous month button should also only be clickable if there were clickable dates in these months. The solution came to me in a dream, no actually a colleague got me on the idea. The answer was in the events.

Heres the code:

 
private void calDueDate_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e) {
   DateTime dt = Convert.ToDateTime( dueDate );
   if( dt <= DateTime.Today.AddDays(30) ){
      e.Day.IsSelectable = false;
   }
}

private void calDueDate_VisibleMonthChanged(object sender, System.Web.UI.WebControls.MonthChangedEventArgs e) {
   DateTime dt = Convert.ToDateTime( pageTask.DueDate);
   if( dt <= DateTime.Today){
      calDueDate.NextMonthText= "" 
      calDueDate.NextMonthText= ">";
}
else{
      calDueDate.NextMonthText = "";
      calDueDate.PrevMonthText = "<"; 
   } 
} 
private void  calDueDate_Load(object sender, System.EventArgs e) { 
   calDueDate.PrevMonthText = ""; 
}
I must say, the AJAX Calendar looks pretty sweet as well: http://ajax.asp.net/ajaxtoolkit/Calendar/Calendar.aspx

Friday, July 25, 2008 4:20:21 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
.NET | ASP.NET
Comments are closed.
Navigation
Archive
<July 2010>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Gaute Magnussen
Sign In
Statistics
Total Posts: 17
This Year: 0
This Month: 0
This Week: 0
Comments: 1
Themes
Pick a theme:
All Content © 2010, Gaute Magnussen
DasBlog theme 'Business' created by Christoph De Baene (delarou)