Showing posts with label jQuery UI Datepicker. Show all posts
Showing posts with label jQuery UI Datepicker. Show all posts

Wednesday, July 11, 2012

Asp.Net jQuery UI Datepicker position adjustment


In this post Asp.Net jQuery UI Datepicker position adjustment we shall see on how to alter the display position of the datepicker control.

By default the datepicker is displayed just below the textbox controls to which it is tagged to, we can alter the position  of the datepicker by altering the marginTop & marginLeft properties of the datepicker.

Add an asp:TextBox control to the page and add the below jQuery script.



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Date Picker</title>
    <link type="text/css"
href="css/smoothness/jquery-ui-1.8.21.custom.css"
rel="Stylesheet" />
    <script
type="text/javascript"
src="JavaScript/jquery-1.7.2.js"></script>
    <script
type="text/javascript"
src="JavaScript/jquery-ui-1.8.21.custom.min.js"></script>
    <link
type="text/css"
href="Stylesheet.css"
rel="Stylesheet" />
    <script type="text/javascript">
        $(function() {
           $("#txtDatePickerPosition").datepicker({
                changeYear: true,
                beforeShow: function(input, inst) {
                        inst.dpDiv.css({
                        marginTop: (-input.offsetHeight) + 'px',
                        marginLeft: input.offsetWidth + 'px'
                    });
                }
            });
        });
      </script>
</head>
<body>
    <form id="frmDatePicker" runat="server">
        <table>
            <tr>
                <td>Date Picker Position</td>
                <td><asp:TextBox
                    id="txtDatePickerPosition"
                    runat="server"
                    ReadOnly="true"></asp:TextBox>
                </td>               
            </tr>                                        
  </table>
    </form>
</body>
</html>


Asp.Net jQuery UI Datepicker size adjustment


In this post Asp.Net jQuery UI Datepicker size adjustment we shall see on how to alter the size of the datepicker control.

The default datepicker looks big, we can alter the size of the datepicker by altering the font size of the text in the datepicker, The size can be altered by adding the following css style either to the page or to a .css file

div.ui-datepicker
{
      font-size:11px;
}

The following diagram shows the size difference before and after applying the style.



For a full example covering all posible scenarios in using a jQuery UI Datepicker control refer to the post Asp.Net jQuery UI Datepicker Tutorial.


Asp.Net jQuery UI Datepicker date format


In this post Asp.Net jQuery UI Datepicker date format we shall see on how to set the format in which the datepicker should return the selected date.

By default the datepicker will return the date in mm/dd/yyyy format,  you can use the dateFormat property to alter the format in which the date is returned.

mm-dd-yy – Returns 07-01-2012
dd-M-yy  - Returns 11-Jul-2012

For a list of the possible formats which can be used refer to the jQuery UI datepicker documentation http://docs.jquery.com/UI/Datepicker/formatDate

Add an asp:TextBox control to the page and add the below jQuery script.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Date Picker</title>
    <link type="text/css"
href="css/smoothness/jquery-ui-1.8.21.custom.css"
rel="Stylesheet" />
    <script
type="text/javascript"
src="JavaScript/jquery-1.7.2.js"></script>
    <script
type="text/javascript"
src="JavaScript/jquery-ui-1.8.21.custom.min.js"></script>
    <link
type="text/css"
href="Stylesheet.css"
rel="Stylesheet" />
    <script type="text/javascript">
        $(function() {
$("#txtDateFormat1").datepicker({ dateFormat: "mm-dd-yy" });
        });
      </script>
</head>
<body>
    <form id="frmDatePicker" runat="server">
        <table>
            <tr>
                <td>Date Format (mm-dd-yy)</td>
                <td><asp:TextBox
                    id="txtDateFormat1"
                    runat="server"
                    ReadOnly="true"></asp:TextBox>
                </td>               
            </tr> 
  </table>
    </form>
</body>
</html>

For a full example covering all posible scenarios in using a jQuery UI Datepicker control refer to the post Asp.Net jQuery UI Datepicker Tutorial.

Asp.Net jQuery UI Datepicker default date


In this post Asp.Net jQuery UI Datepicker default date we shall see on how to set a default date when the datepicker opens up.

By default the datepicker will display the current system date as the default date, we can set out own default date by setting the defaultDate property.
Add an asp:TextBox control to the page and add the below jQuery script.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Date Picker</title>
    <link type="text/css"
href="css/smoothness/jquery-ui-1.8.21.custom.css"
rel="Stylesheet" />
    <script
type="text/javascript"
src="JavaScript/jquery-1.7.2.js"></script>
    <script
type="text/javascript"
src="JavaScript/jquery-ui-1.8.21.custom.min.js"></script>
    <link
type="text/css"
href="Stylesheet.css"
rel="Stylesheet" />
    <script type="text/javascript">
        $(function() {
$("#txtDefaultDate").datepicker({ defaultDate: new Date(2007, 0, 1) });
        });
      </script>
</head>
<body>
    <form id="frmDatePicker" runat="server">
        <table>
            <tr>
                <td>Default Date (01/01/2007)</td>
                <td><asp:TextBox
                    id="txtDefaultDate"
                    runat="server"
                    ReadOnly="true"></asp:TextBox>
                </td>               
            </tr>             
  </table>
    </form>
</body>
</html>

For a full example covering all posible scenarios in using a jQuery UI Datepicker control refer to the post Asp.Net jQuery UI Datepicker Tutorial.