SIGN UP MEMBER LOGIN:    
ARTICLE

Datepicker in Expression Web using jQuery

Posted by Manoj Singh Panwar Articles | Expression Studio December 05, 2011
In this article you will learn how to use jQuery to add a Datepicker in Expression Web 4.
Reader Level:

Hi guys, In this article you will learn how to use jQuery to add a Datepicker in Expression Web4. It is not a big deal to work out but quite interesting for the beginners. Here I have used the Datepicker in through the Record form entry in which validation is also used to give much better look to the user.

Follow the steps below to implement this application:

Step 1 : Open a new HTML page by selecting File--> New-->Page--> HTML.

file-open.gif

Step 2 : Now in the page so opened, add a <div></div> tag to give nice look to the form.

Step 3 : Then add textbox from the toolbox and arrange them in this way aside the Text fields.

form.gif

Step 4 : Now type the following code in the code panel.

xml.gif

Step 5 : Here what happens in the code is that a text box named "tbDate" is bind with the Datepicker control and functionality is added to the Datepicker such that it will display list of previous six years and next three years from the current year. Also the code calendar is displayed as soon as the textbox is clicked.

Step 6 :  Now adding Validation to the texboxes. Add validations to these fields :

  • State : Required field validator
  • pin code : Required field validator
  • Email Id : Regular Expression Validator Of Internet Email Format
validation.gif

Step 7 : Now add a button so that the page refreshes to check for validation :

button.gif

Step 9 : The complete code in HTML is  as follows:

<!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>\
        <title>Using DatePicker in Expression Web using jQuery </title>
            <
script type="text/javascript"
                src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">
            </
script>
            <
script type="text/javascript"
               
src="http://ajax.microsoft.com/ajax/jquery.ui/1.8.6/jquery-ui.min.js">
            </
script>
            <
script type="text/javascript">

                $(
function ()
                {
                        var options = {
                        numberOfMonths: 1,
                        changeYear:
true,
                        yearRange:
"-6+3",
                                       }

                            $(
"#tbDate").datepicker(options);
     
       </script>
             <
style type="text/css">
                .auto-style1 {
                font-size: xx-large;
                             }

                .auto-style2 {
                margin-left: 131px;
                             }

                .auto-style3 {
                margin-left: 117px;
                             }
            </style>
     </
head>
     <
body bgcolor="#999999">\
      <form id="form1" runat="server" class="auto-style3" style="height: 784px; width: 500px">
       <
div style="width: 473px; height: 75px; color: #CC3300; background-color: #003300; position: fixed; left: 142px; top: 15px;">
           <
br />    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs;&nbsp;&nbsp;&nbsp;&nnbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span class="auto-style1">Record Form</span></div>
            <
br /><br /><br /><br />

                      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <div class="auto-style2" style="width: 475px; height: 706px; color: #000000; background-color: #C0C0C0; font-size: x-large; position:   
          fixed;
left:10px; top: 91px;">Personal Information:<br /><br />
                First Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:TextBox id="TextBox1" runat="server"></asp:TextBox><br /><br />
                Last Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:TextBox id="TextBox2" runat="server"></asp:TextBox><br /><br />
                Date of birth&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <
input id="tbDate" type="text" /><br /><br />
                Email&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:TextBox id="TextBox3" runat="server"></asp:TextBox>
            <
asp:RegularExpressionValidator id="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox3" ErrorMessage="*"
                ForeColor="#CC3300"></asp:RegularExpressionValidator><br /><br />
                Address&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:TextBox id="TextBox4" runat="server"></asp:TextBox><br /><br />
                City&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:TextBox id="TextBox5" runat="server"></asp:TextBox><br /><br />
                State&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:TextBox id="TextBox8" runat="server"></asp:TextBox>
            <
asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox8" ErrorMessage="*"\
                    ForeColor="#CC3300"></asp:RequiredFieldValidator><br /><br />
               
Pin code&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:TextBox id="TextBox7" runat="server"></asp:TextBox>
            <
asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox7" ErrorMessage="*"\
                    ForeColor="#CC3300"></asp:RequiredFieldValidator><br /><br />&nbsp;&nbsp; <br />
            <
asp:Button id="Submit" runat="server" BackColor="Black" BorderStyle="None" Font-Bold="True" Font-Underline="True" ForeColor="White"                     Text="Button"/>
            </
div>
      </
form>
    </
body>
</
html>

Step 10 : Now click on the preview button and see the output in the browser:

Output1:

OUTPUT1.gif

Output 2:

OUTPUT2.gif

Output3:

OUTPUT3.gif

Login to add your contents and source code to this article
share this article :
post comment
 

Hi, I have attached the source code ..please refer to it and I hope it will solve your problem. Still in case of problem feel free to ask..

Posted by Manoj Singh Panwar Dec 13, 2011

I have copied the same code (what you mentioned in sample app), but i am not getting any DatePicker popup while clicking on "tbDate" textbox. Can you please tell me, if i miss any thing? If possible, can you please attach the code files. Thank you, Ravi

Posted by ravi kumar Dec 08, 2011

May I know what error you had doing this. and may be you are missing something in step 4. Just sent me the error and I'll try ma best to take you out of this prob.

Posted by Manoj Singh Panwar Dec 07, 2011

I have tried it, but it is not working for me.

Posted by ravi kumar Dec 07, 2011

Hi. if you notice the line -----" $("#tbDate").datepicker(options);"----- you'll come to know that the tbDate is bind to datepicker property. this line is after the function:---------- $(function () { var options = { numberOfMonths: 1, changeYear: true, yearRange: "-6+3", }--------

Posted by Manoj Singh Panwar Dec 07, 2011
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Team Foundation Server Hosting
Become a Sponsor