Hello,
I am using infragistics 7.2.20072.61 on a asp.net website. Currently I have a criteria list that generates controls based on the selected list. When selecting a list that has a date criteria I dynamically create a webDateChooser in code. I have a javascript function that limits the dates that a user can select and changes the color of invalid ones, but I can't seem to implement it properly in code only in html.
BLOCKED SCRIPT
function WebDateChooser1_CalendarRenderDay(oCalendar, oDay, oEvent){
var outOfRange = false; var min = oCalendar.MinDate; if(min && oDay.year <= min.getFullYear()) { if(oDay.year < min.getFullYear()) outOfRange = true; else if(oDay.month <= min.getMonth() + 1) { if(oDay.month < min.getMonth() + 1) outOfRange = true; else if(oDay.day < min.getDate()) outOfRange = true; } } var max = oCalendar.MaxDate; if(!outOfRange && max && oDay.year >= max.getFullYear()) { if(oDay.year > max.getFullYear()) outOfRange = true; else if(oDay.month >= max.getMonth() + 1) { if(oDay.month > max.getMonth() + 1) outOfRange = true; else if(oDay.day > max.getDate()) outOfRange = true; } }
oDay.element.disabled = false;
var len;var Datenow = oDay.day + '/' + oDay.month + '/' + oDay.year;for (var i=0, len=HolidayDays.length; i<len; ++i ){ if(HolidayDays[i] == Datenow) { oDay.element.disabled = true; }}
if (oDay.dow == 0 || oDay.dow == 6) oDay.element.disabled = true;
oDay.element.style.color= outOfRange ? "#C0C0C0" : "Black";
}
CODE:
Dim DateT As New Infragistics.WebUI.WebSchedule.WebDateChooser() DateT.ID = "txt" & i.ToString & strListID DateT.MaxDate = GetLastBusinessDay(Today, 2) DateT.MinDate = GetMinDate() DateT.Value = DateT.MaxDate DateT.Width = Unit.Pixel(150) DateT.Attributes.Add("CalendarRenderDay", "WebDateChooser1_CalendarRenderDay();") tc.Controls.Add(DateT)
This doesn't work in code but if I build it in html (which isnt an option) it works :
HTML
<igsch:WebDateChooser ID='DATE' runat='server' MinDate="2008-01-01" CalendarLayout-Culture="" OnLoad="DateChooser_Load" Editable="false" > <ClientSideEvents CalendarRenderDay="WebDateChooser1_CalendarRenderDay" /> </igsch:WebDateChooser>
Do I need to pass in these oCalander, oDate and oEvent arguments? if so where do I get these values?
Thanks in advance!
HI, when you dynamically allocate the WebDateChooser - sets its mindate and maxdate properties
Here is a help link:
http://help.infragistics.com/Help/NetAdvantage/NET/2008.3/CLR2.0/html/Infragistics2.WebUI.WebDateChooser.v8.3~Infragistics.WebUI.WebSchedule.WebDateChooser~MaxDate.html
http://help.infragistics.com/Help/NetAdvantage/NET/2008.3/CLR2.0/html/Infragistics2.WebUI.WebDateChooser.v8.3~Infragistics.WebUI.WebSchedule.WebDateChooser~MinDate.html
Here is a kb article on disabling individiual dates
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=10064
I am actually having trouble getting the control do distiguish the disabled dates from non-disabled ones, not in actually disabling them. The code I posted manages to disable all the dates properly. However when the control is dynamically created the javascript attribute that I have added to color the doesnt seem to fire properly (i have verified this works by adding it manually in html and it colors the dates properly). So my question is "why is my javascript attribute that I add to the control event CalanderRenderDay not firing?"
This is the vb.net code in question:
DateT.Attributes.Add("CalendarRenderDay", "WebDateChooser1_CalendarRenderDay();")
You can see the javascript function it is calling in the post above.
Thanks.
HI ,
You need to show the parameters
DateT.Attributes.Add("oncalendarrenderday", "WebDateChooser1_CalendarRenderDay(oCalendar,Day,Event");
I created sample project - I tested this and it worked
Here is my aspx page :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register assembly="Infragistics2.WebUI.WebDateChooser.v8.3, Version=8.3.20083.1009, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.WebUI.WebSchedule" tagprefix="igsch" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title>
<script type="text/javascript" id="igClientScript"><!--
<!--
function WebDateChooser1_CalendarRenderDay(oCalendar, oDay, oEvent){ //Add code to handle your event here. debugger; //var min = oCalendar.getMinDate(); //var max = oCalendar.getMaxDate(); var mindate = oCalendar.MinDate.getDate(); // alert(oCalendar.MinDate); if (oDay.day < mindate || oDay.day > oCalendar.MaxDate.getDate()) { oDay.element.disabled = true; oDay.element.style.cursor = "not-allowed"; } else { oDay.element.disabled = false; oDay.element.style.cursor = "hand"; }
}// -->
function WebDateChooser1_InitializeDateChooser(oDateChooser){ //Add code to handle your event here. debugger;}// --></script></head><body> <form id="form1" runat="server"> <div> </div> </form></body></html>
Here is my code-behind:
using System;using System.Configuration;using System.Data;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using Infragistics.WebUI.WebSchedule;
public partial class _Default : System.Web.UI.Page { protected void Page_Init(object sender, EventArgs e) { WebDateChooser wdc = new WebDateChooser(); wdc.MinDate = DateTime.Now.AddDays(-4); wdc.MaxDate = DateTime.Now.AddDays(5); wdc.ID = "wdc"; // wdc.CalendarLayout.d wdc.ClientSideEvents.CalendarRenderDay = "WebDateChooser1_CalendarRenderDay"; wdc.Attributes.Add("oncalendarrenderday", "WebDateChooser1_CalendarRenderDay(oCalendar,Day,Event"); // this.Controls.Add(wdc);
wdc.ClientSideEvents.InitializeDateChooser = "WebDateChooser1_InitializeDateChooser"; wdc.Attributes.Add("oninitializedatechooser", "WebDateChooser1_InitializeDateChooser"); this.form1.Controls.Add(wdc); } protected void Page_Load(object sender, EventArgs e) { }}
Thanks a ton! Works perfect!