Saturday, December 1, 2012

Disable custom dates in jquery UI datepicker using C# and SQL Server

Here i will show how to disable Custom dates in jquery UI datepicker from database SQL Server and C#.Net.......





<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="DisableHolidays._Default" %>
 
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
 <link href="css/smoothness/jquery-ui-1.8.23.custom.css" rel="stylesheet" type="text/css" />
    <link href="css/DatePickerSize.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery-ui-1.8.23.custom.min.js" type="text/javascript"></script>
 
    <script type="text/javascript">
var days = ["Sunday""Monday""Tuesday""Wednesday""Thursday""Friday""Saturday""Sunday"];
var unavailableDates = ["2012/12/24""2012/12/25""2012/12/13""2013/01/01"]; // yyyy/MM/dd
var unavailableDays = ["Saturday""Sunday"];
 
        function unavailable(date) {
            ymd = date.getFullYear() +  
                                      "/" + ("0" + (date.getMonth() + 1)).slice(-2) + 
                                      "/" + ("0" + date.getDate()).slice(-2);
            day = new Date(ymd).getDay();
            if ($.inArray(ymd, unavailableDates) 
                             < 0 && $.inArray(days[day], unavailableDays) < 0) {
                return [true"enabled""Working Day"];
            } else {
                return [false"disabled""HoliDay"];
            }
        }
 
        $(document).ready(function () {
            $('[id$=TextBox1]').datepicker({
                beforeShowDay: unavailable,
                dateFormat: 'mm-dd-yy',
                changeMonth: true,
                changeYear: true
            });
        });
    </script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <center>
        <asp:HiddenField ID="HiddenField1" runat="server" />
        <h3>
        <li>disable weekends</li>
        <li>public holidays</li>
        <li>custom holidays</li>
        </h3>
        <br />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </center>
</asp:Content>

No comments:

Post a Comment