Friday, April 16, 2010

How to change color of dates which are greater than current date in Ajax calender extender

The following code will help you ,just put in inside in your page :

Include folowing stylesheet in your page :


      .ajax_Ena div
      {
        background:gray;
        cursor:text;   
      }
    

Include following code inside script :

     AjaxControlToolkit.CalendarBehavior.prototype._performLayout = function()
            {                      
                             
                 var elt = this.get_element();                                                                                  
                 if (!elt) return;
                 else
                 {
                    if (!this.get_isInitialized()) return;  
                    if (!this._isOpen) return;              
                    var dtf = Sys.CultureInfo.CurrentCulture.dateTimeFormat;
                                       
                    var selectedDate = this.get_selectedDate();  
                    var visibleDate = this._getEffectiveVisibleDate();  
                    var todaysDate = this.get_todaysDate();                             
                         switch (this._mode)
                         {  
                             case "days":  
                                   
                                 var firstDayOfWeek = this._getFirstDayOfWeek();  
                                 var daysToBacktrack = visibleDate.getDay() - firstDayOfWeek;  
                                 if (daysToBacktrack <= 0)  
                                     daysToBacktrack += 7;  
                                       
                                 var startDate = new Date(visibleDate.getFullYear(), visibleDate.getMonth(), visibleDate.getDate() - daysToBacktrack, this._hourOffsetForDst);                   
                                 var currentDate = startDate;                            
                                  
                                 for (var i = 0; i < 7; i++)
                                 {  
                                     var dayCell = this._daysTableHeaderRow.cells[i].firstChild;  
                                     if (dayCell.firstChild)
                                     {  
                                         dayCell.removeChild(dayCell.firstChild);  
                                     }  
                                     dayCell.appendChild(document.createTextNode(dtf.ShortestDayNames[(i + firstDayOfWeek) % 7]));  
                                 }  
                                
                                 for (var week = 0; week < 6; week ++)
                                 {  
                                     var weekRow = this._daysBody.rows[week];  
                                     for (var dayOfWeek = 0; dayOfWeek < 7; dayOfWeek++)
                                     {  
                                         var dayCell = weekRow.cells[dayOfWeek].firstChild;  
                                         if (dayCell.firstChild)
                                         {  
                                             dayCell.removeChild(dayCell.firstChild);  
                                         }  
                                         dayCell.appendChild(document.createTextNode(currentDate.getDate()));  
                                         dayCell.title = currentDate.localeFormat("D");  
                                         dayCell.date = currentDate;                                                                                                     
                                         $common.removeCssClasses(dayCell.parentNode, [ "ajax__calendar_hover" ,"ajax__calendar_other", "ajax__calendar_active"]);                       
                                        
                                     
                                         if(elt.id.toLowerCase().indexOf('sdate') > -1)
                                         {
                                            var today_date = ('<%=GetTodayDate(1) %>');                                                                                                
                                            if(currentDate > new Date())
                                            {
                                                Sys.UI.DomElement.addCssClass(dayCell.parentNode,"ajax_Ena");                                                                                                                      
                                            }
                                            else
                                            {
                                            $common.removeCssClasses(dayCell.parentNode,["ajax_Ena"]);
                                            }
                                          }                                          
                                         currentDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate() + 1, this._hourOffsetForDst);  
                                     }  
                                 }  
                                   
                                 this._prevArrow.date = new Date(visibleDate.getFullYear(), visibleDate.getMonth() - 1, 1, this._hourOffsetForDst);  
                                 this._nextArrow.date = new Date(visibleDate.getFullYear(), visibleDate.getMonth() + 1, 1, this._hourOffsetForDst);  
                                 if (this._title.firstChild)
                                 {  
                                     this._title.removeChild(this._title.firstChild);  
                                 }  
                                 this._title.appendChild(document.createTextNode(visibleDate.localeFormat("MMMM, yyyy")));  
                                 this._title.date = visibleDate;  
                   
                                 break;  
                             case "months":                   
                                 for (var i = 0; i < this._monthsBody.rows.length; i++)
                                 {  
                                     var row = this._monthsBody.rows[i];  
                                     for (var j = 0; j < row.cells.length; j++)
                                     {  
                                         var cell = row.cells[j].firstChild;  
                                         cell.date = new Date(visibleDate.getFullYear(), cell.month, 1, this._hourOffsetForDst);  
                                         cell.title = cell.date.localeFormat("Y");                                                              
                                         $common.removeCssClasses(cell.parentNode, [ "ajax__calendar_other", "ajax__calendar_active" ]);  
                                         Sys.UI.DomElement.addCssClass(cell.parentNode, this._getCssClass(cell.date, 'M'));  
                                     }  
                                 }  
                                   
                                 if (this._title.firstChild)
                                 {  
                                     this._title.removeChild(this._title.firstChild);  
                                 }  
                                 this._title.appendChild(document.createTextNode(visibleDate.localeFormat("yyyy")));  
                                 this._title.date = visibleDate;  
                                 this._prevArrow.date = new Date(visibleDate.getFullYear() - 1, 0, 1, this._hourOffsetForDst);  
                                 this._nextArrow.date = new Date(visibleDate.getFullYear() + 1, 0, 1, this._hourOffsetForDst);  
                   
                                 break;  
                             case "years":  
                   
                                 var minYear = (Math.floor(visibleDate.getFullYear() / 10) * 10);  
                                 for (var i = 0; i < this._yearsBody.rows.length; i++)
                                 {  
                                     var row = this._yearsBody.rows[i];  
                                     for (var j = 0; j < row.cells.length; j++)
                                     {  
                                         var cell = row.cells[j].firstChild;  
                                         cell.date = new Date(minYear + cell.year, 0, 1, this._hourOffsetForDst);  
                                         if (cell.firstChild)
                                         {  
                                             cell.removeChild(cell.lastChild);  
                                         }
                                         else
                                         {  
                                             cell.appendChild(document.createElement("br"));  
                                         }  
                                         cell.appendChild(document.createTextNode(minYear + cell.year));  
                                         $common.removeCssClasses(cell.parentNode, [ ".ajax__calendar_other", ".ajax__calendar_active" ]);  
                                         Sys.UI.DomElement.addCssClass(cell.parentNode, this._getCssClass(cell.date, 'y'));  
                                     }  
                                }  
                   
                                if (this._title.firstChild)
                                {  
                                    this._title.removeChild(this._title.firstChild);  
                                }  
                                this._title.appendChild(document.createTextNode(minYear.toString() + "-" + (minYear + 9).toString()));  
                                this._title.date = visibleDate;  
                                this._prevArrow.date = new Date(minYear - 10, 0, 1, this._hourOffsetForDst);  
                                this._nextArrow.date = new Date(minYear + 10, 0, 1, this._hourOffsetForDst);  
                   
                            break;  
                         }  
                         if (this._today.firstChild)
                         {  
                             this._today.removeChild(this._today.firstChild);  
                         }  
                         this._today.appendChild(document.createTextNode(String.format(AjaxControlToolkit.Resources.Calendar_Today, todaysDate.localeFormat("MMMM d, yyyy"))));  
                         this._today.date = todaysDate;                                                           
                 }             
            }


 


If you have any query than just mail me or post comment....

No comments:

Post a Comment