datepicker works in standalone aspx file but not when associated with a Master Page VS Studio 2010 C#

datepicker works in standalone aspx file but not when associated with a Master Page VS Studio 2010 C#

I'm working with code from a supplier who created the shell of a working website. I need to add a date range to one of the reports. 

The web site has a Master Page (ASP.NET)where it uses the form tag that begins and ends on the Master Page.

The page where I want to add two date fields is started and ended with <asp:Content></asp:Content>.  The fields for the two dates work on a separate aspx page where I can use the form tag and there is no <asp:Content> section. That exact code does not work between the <asp:Content> and </asp:Content> tags in the web site code.

Here is my separate calendar.aspx. This code does not work between <asp:Content> tags and a Master Page already have a form tag which causes VS 2010 c# to disallow the one in this code.

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.   <title>jQuery UI Datepicker - Display month &amp; year menus</title>
  5.   <link rel="stylesheet" href="//code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css"/>
  6.   <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  7.   <script src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
  8.   <link rel="stylesheet" href="/resources/demos/style.css" />
  9.   <script>
  10. $(function() {
  11.     $("#SearchFromdateTextBox").datepicker({
  12.           changeMonth: true,
  13.           changeYear: true
  14.       });
  15. });

  16. $(function() {
  17.     $("#SearchToDateTextBox").datepicker({
  18.             changeMonth: true,
  19.           changeYear: true
  20.       });
  21. });

  22. function isDateCheck(txta) {
  23.     var dateString = document.getElementById(txta).value;
  24.     // First check for the pattern
  25.     if (!/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(dateString))
  26.         return false;

  27.     // Parse the date parts to integers
  28.     var parts = dateString.split("/");
  29.     var day = parseInt(parts[1], 10);
  30.     var month = parseInt(parts[0], 10);
  31.     var year = parseInt(parts[2], 10);

  32.     // Check the ranges of month and year
  33.     if (year < 1000 || year > 3000 || month == 0 || month > 12)
  34.         return false;

  35.     var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

  36.     // Adjust for leap years
  37.     if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
  38.         monthLength[1] = 29;

  39.     // Check the range of the day
  40.     return day > 0 && day <= monthLength[month - 1];
  41. }
  42. function checkdatepicker(){
  43.     if (!isDateCheck("SearchFromdateTextBox")) {
  44.         document.getElementById("SearchFromdateTextBox").style.backgroundColor = "yellow";
  45.         document.getElementById("SearchFromdateTextBox").focus();
  46.         return false;
  47.     } else {
  48.         document.getElementById("SearchFromdateTextBox").style.backgroundColor = "white";
  49.         return true;
  50.     }
  51. }
  52. function checkdatepicker1() {
  53.     if (!isDateCheck("SearchToDateTextBox")) {
  54.         document.getElementById("SearchToDateTextBox").style.backgroundColor = "yellow";
  55.         document.getElementById("SearchToDateTextBox").focus();
  56.           return false;
  57.       } else {
  58.           document.getElementById("SearchToDateTextBox").style.backgroundColor = "white";
  59.           return true;
  60.       }
  61. }

  62. function compareDate() {
  63.     var start = document.getElementById("SearchFromdateTextBox").value;
  64.     var end = document.getElementById("SearchToDateTextBox").value;
  65.     var curdate = new Date();
  66.     var stDate = new Date(start);
  67.     var enDate = new Date(end);
  68.     var compDate = enDate - stDate;
  69.     if (compDate >= 0 && enDate <= curdate) {
  70.         return true;
  71.     } else {
  72.         alert("The 'To date' must be greater than or equal to the 'From date' and less than or equal to the system date. Please correct the 'To date'.");
  73.         //document.getElementById("datepicker1").value = "";
  74.         document.getElementById("datepicker1").focus();
  75.         return false;
  76.     }
  77. }


  78.   </script>
  79. </head>
  80. <body>

  81. <form runat="server">
  82. <table runat="server" id="JQDateTable" visible="true">
  83.  <tr><td colspan="4"><h1 align="center">Transactions by date</h1></td></tr>
  84.     <tr class="maxWidth">
  85.         <td>
  86.             <asp:Label runat="server" ID="SearchFromdateLabel" Text="From date :" CssClass="labelClass"></asp:Label>
  87.         </td>
  88.         <td>
  89.             <asp:TextBox ID="SearchFromdateTextBox" runat="server" CssClass="Report-text-box"></asp:TextBox>
  90.         </td>
  91.         <td>
  92.             <asp:Label runat="server" ID="SearchToDateLabel" Text="To date :" CssClass="labelClass"></asp:Label>
  93.         </td>
  94.         <td>
  95.             <asp:TextBox ID="SearchToDateTextBox" runat="server"  onfocus="checkdatepicker()" CssClass="Report-text-box"></asp:TextBox>
  96.         </td>
  97.         <td>
  98.             <asp:Button ID="SearchButton" runat="server" CssClass="btn-Report" Text="Search"  onfocus="checkdatepicker1()" />
  99.         </td>
  100.         <td>
  101.             <asp:Button ID="CancelButton" runat="server" CssClass="btn-Report" Text="Cancel" />
  102.         </td>
  103.     </tr>
  104. <%-- <tr class="maxWidth">
  105.     <td>
  106.         From date: <input type="text" id="datepicker" />       
  107.     </td>
  108.     <td>
  109.         To date: <input type="text" id="datepicker1" onfocus="checkdatepicker()"/>
  110.     </td>
  111.     <td>
  112.          <input type="button" id="SearchButton" class="btn-Report" value="Search" onfocus="checkdatepicker1()" onclick="compareDate()" />
  113.     </td>
  114.     <td>
  115.          <input type="button" id="CancelButton" class="btn-Report" value="Cancel" onclick="compareDate()" />
  116.     </td>
  117.  </tr>OnClick="SearchButton_Click()" onclick="return compareDate();"OnClick="CancelButton_Click()"

  118. </table>
  119. </form>

  120. </body>

  121. </html>

  122. Bob