The following example demonstrates how to disable all Sundays within the Calendar and use the Microsoft CustomValidator to ensure a Sunday was not selected by any other method (eg. typing directly into the TextBox, or keyboard shortcuts).
The Sunday(s) within the Calendar are disabled by using the OnClientDayRender property and firing the custom JavaScript function disableSundays() for each day rendered. If the date being rendered/built is a Sunday, the date is disabled by replacing the hyperlink with the day number.
The Microsoft CustomValidator is used to validate the value in the TextBox to ensure a Sunday was not typed into the TextBox. The CustomValidator fires the disableSundaysValidation() function when the page is submitted. Within the disableSundaysValidation() function, the SelectedDate of the Date Picker is obtained and checked to see if it's a Sunday. If a Sunday, the page is set to invalid.
If you want to disable both Saturday and Sundays, please set the SelectableWeekendDays property to false.
<%@ Page Language="C#" %>
<%@ Register Assembly="BasicFrame.WebControls.BasicDatePicker" Namespace="BasicFrame.WebControls" TagPrefix="BDP" %>
<!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>Disable all Sundays with OnClientDayRender</title>
<script type="text/javascript">
function disableSundays(sender, args)
{
if(args.date.is().sunday()) {
// If the cell is a Sunday, disable by setting
// the cell contents to the day number.
args.cell.innerHTML = args.date.getDate();
}
return args.cell;
}
function disableSundaysValidation(sender, args)
{
if(BasicDatePicker1.getSelectedDate().is().sunday())
{
args.IsValid = false;
return;
}
args.IsValid = true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<p><BDP:BasicDatePicker ID="BasicDatePicker1" runat="server" OnClientDayRender="disableSundays" />
<asp:CustomValidator
ID="CustomValidator1"
runat="server"
ClientValidationFunction="disableSundaysValidation"
ControlToValidate="BasicDatePicker1"
ErrorMessage="Please select a day other than a Sunday." />
</p>
<p><asp:Button ID="Button1" runat="server" Text="Submit" /></p>
</form>
</body>
</html>
OnClientDayRender | SelectableWeekendDays