title: Javascript to validate start date and end date in asp.net
body: <p>I have written a JS that should check that start date is less than end date. If not, alert should be thrown</p>
  
  <p>The JS is written as;</p>
  
  <pre><code>function DateValidation(startDate, EndDate) {
                  debugger;
                  var stdate = startDate;
                  var enddate = EndDate;
                  if (stdate!= '' &amp;&amp; enddate!='') {
                  if (stdate &gt; enddate) {
                      alert('Start date cannot be greater than end date');
                      return false;
                  }
                  else {
                      return true;
                  }
                 }
              }
  </code></pre>
  
  <p>This JS gets fired when i am clicking a button as "Show Report".</p>
  
  <p>Problems that i am facing</p>
  
  <ol>
  <li><p>JS doesn't validate the date correctly. What am i missing? i am passing date from the textbox</p></li>
  <li><p>The JS doesn't fired up when clicking button for the first time. it fires when clicking the button second time</p></li>
  </ol>
  
  <p>Plus, i have registered the JS as below;</p>
  
  <pre><code>btnShowReport.Attributes.Add("onclick", "return DateValidation('" + txtStartDate.Text + "', '" + txtEndDate.Text + "');");
  </code></pre>
  
  <p>Is the above code correct? What is the correct place to register the JS?</p>
  
  <p>Please guide.. thanks!</p>