To keep check on the value entered in textbox

I have two fields in my form , one for joining date and another for leaving date...I want to keep a check that leaving date entered should not be greater than the joining date...For that i have used WEB METHOD
Transfer_Flat.aspx
Transfer_Flat.aspx.cs
Sukesh ShuklaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
OK.  So what is the question?
Sukesh ShuklaAuthor Commented:
How to perform that coding for check....I did it using web method , but it is not working...

I found one mistake i gave wrong name to my web method , but after correcting also its not working
Julian HansenCommented:
Do you want this client side or server side - you have posted to the AJAX zone which implies it has something to do with the server but checking dates is easily done in the browser.

You could do something like this.
Remove the onchange and replace with a jQuery event handler that checks the date before processing
<script>
$(function() {
  $('#<%=TextBoxLD.ClientID%>').change(function() {
    //This function call on text change.             
   // Check if the joindate is 
    if (new Date($('#<%=TextBoxJ.ClientID%>').val()) > new Date($(this).val())) {
      alert('Join Date must preceed Leave Date');
      return false;
    }
    $.ajax({
      type: "POST",
      url: "Transfer_Flat.aspx/CheckDate", // this for calling the web method function in cs code.  
      data: '{date: "' + $("#<%=TextBoxLD.ClientID%>")[0].value + '"}',// flat name 
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      failure: function (response) {
        alert(response);
      }
    }).done(function(response) {
      OnSuccess(response);
    });
  });
});

function OnSuccess(response)
{
  // On success code here
}
</script>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Sukesh ShuklaAuthor Commented:
Could you please tell where to call this jquery function ......
Julian HansenCommented:
You don't call it - you bind an event handler to the change event of the element you want to run the function against.

So in the code below (Line 3 from the source above) - we are telling jQuery to bind the function to the change event of the element identified by TextBoxLD.ClientID.
Now, whenever that textbox's value changes the function is called automatically.

 $('#<%=TextBoxLD.ClientID%>').change(function() {

Open in new window

Sukesh ShuklaAuthor Commented:
Thanks a lot Julian ...... I got it
Julian HansenCommented:
You are welcome.
Sukesh ShuklaAuthor Commented:
Please help me with this problem too:-

While retreiving data from database , i'm checking 3 conditions together, but the data is not getting displayed in gridview...
 protected void Page_Load(object sender, EventArgs e)
        {
            GetResults();
        }

        private void GetResults()
        {

            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HousingConnectionString"].ConnectionString);
            conn.Open();
            string query;
            SqlCommand com;
            SqlDataReader reader;

            SqlDataAdapter adapter = new SqlDataAdapter();



            query = "SELECT Flat ,First_Name , Middle_Name , Last_Name , Mobile_No , Email, DOB , Age , Education ,  Office_Add , Native_Add , PAN_Card , Aadhar_Card , Religion , Business_Job , Married_Unmarried ,  No_Of_Members , Joining_Date ,Leaving_Date from Ex_Primary_Member where Flat='" + Request.QueryString["fnum"] + "' and Joining_Date='" + Request.QueryString["jdate"] + "'  and Leaving_Date='" + Request.QueryString["ldate"] + "'";

            com = new SqlCommand(query, conn);
            adapter.SelectCommand = new SqlCommand(query, conn);

            reader = com.ExecuteReader();

            GridView1.DataSource = reader;


            GridView1.DataBind();

        }

Open in new window

Julian HansenCommented:
This looks like a different question. Please open another question to address this issue.
Sukesh ShuklaAuthor Commented:
The script you mentioned above for jquery has again stopped working , please help me ...I'm attatching my code below...Please Help
<script type="text/javascript">
        function SetDate() {
            var date = new Date();

            var day = date.getDate();
            var month = date.getMonth() + 1;
            var year = date.getFullYear();

            if (month < 10) month = "0" + month;
            if (day < 10) day = "0" + day;

            var today = day + "/" + month + "/" + year;


            document.getElementById('TextBoxLD').value = today;
        }
    </script>
    <script>

        $(function () {
            $('#<%=TextBoxLD.ClientID%>').change(function () {
               //This function call on text change.             
               // Check if the joindate is 
                if (new Date($('#<%=TextBoxJ.ClientID%>').val()) > new Date($(this).val())) {
                alert('Join Date must preceed Leave Date');
                return false;
                }
               });
               });
    
</script>
</head>
<body style="background-color: #CCFFFF">
    <form id="form1" runat="server">
    <div class="auto-style1">
    
        <div class="auto-style4">
    
        <strong><span class="auto-style5">Transfering Flate</span><br />
        </strong>
        </div>
        <table class="auto-style2" cellpadding="5">
            <tr>
                <td class="auto-style6">Flat No</td>
                <td> <asp:TextBox ID="TextBoxFN" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBoxFN" ErrorMessage="Mandatory" ForeColor="Red"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td class="auto-style6">From</td>
                <td> <asp:TextBox ID="TextBoxF" runat="server"></asp:TextBox>
                    <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Get Owner's Details" CausesValidation="False" />
                </td>
            </tr>
            <tr>
                <td class="auto-style6">Joining Date</td>
                <td> <asp:TextBox ID="TextBoxJ" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="auto-style6">Leaving Date</td>
                <td> <asp:TextBox ID="TextBoxLD" runat="server" onclick="SetDate()"></asp:TextBox>
                   
                </td>
            </tr>
            <tr>
                <td class="auto-style6">TO{Initial Name}</td>
                <td> <asp:TextBox ID="TextBoxT" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBoxT" ErrorMessage="Mandatory" ForeColor="Red"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td class="auto-style3" colspan="2">
                
                    <asp:Button ID="Button2" runat="server" style="text-align: center" Text="Update Existing Member Details" OnClick="Button2_Click" />
                    <br />
                    <br />
            <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/webform1.aspx">Go To Menu</asp:HyperLink>
                </td>
                <td> &nbsp;</td>
            </tr>
        </table>
    
    </div>
    </form>

Open in new window

Julian HansenCommented:
I need to know how it has stopped working?
Is there an error?
Did you change something?

Give me something to go on.
Sukesh ShuklaAuthor Commented:
No i didn't do anything and even there is no error , its just that alert is not shown even if i'm entering wrong date
Julian HansenCommented:
Can you post the rendered HTML (view source) for this page.
Sukesh ShuklaAuthor Commented:
This is the Rendered HTML
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>

</title>
    <style type="text/css">
        .auto-style1 {
            font-size: large;
            background-color: #CCFFFF;
        }
        .auto-style2 {
            width: 100%;
        }
        .auto-style3 {
            width: 431px;
        }
        .auto-style4 {
            text-align: center;
        }
        .auto-style5 {
            text-decoration: underline;
        }
        .auto-style6 {
            width: 431px;
            text-align: center;
        }
    </style>

    <script type="text/javascript">
        function SetDate() {
            var date = new Date();

            var day = date.getDate();
            var month = date.getMonth() + 1;
            var year = date.getFullYear();

            if (month < 10) month = "0" + month;
            if (day < 10) day = "0" + day;

            var today = day + "/" + month + "/" + year;


            document.getElementById('TextBoxLD').value = today;
        }
    

        $(function () {
            $('#TextBoxLD').change(function () {
               //This function call on text change.             
               // Check if the joindate is 
                if (new Date($('#TextBoxJ').val()) > new Date($(this).val())) {
                alert('Join Date must preceed Leave Date');
                return false;
                }
               });
               });
    
</script>
</head>
<body style="background-color: #CCFFFF">
    <form method="post" action="Transfer_Flat.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="Q8oDL0nc6f485z1lyUYLmzWYFZQ6pAgte1kF0GQzMsp0RanCPFGZ981nY46ixphfJjlQ01abqvsMpYmTLizZKuXNsS5HQ0Qxa347hn2xHUg=" />
</div>

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>


<script src="/WebResource.axd?d=pynGkmcFUV13He1Qd6_TZCErUIiy0FccU42WH3R0u--CN1Jpl8tXLOXbLTNp_FIXJfC4VDiTZJY1l2ou5pl0dw2&amp;t=634773918900000000" type="text/javascript"></script>


<script src="/Scripts/jquery-1.7.1.js" type="text/javascript"></script>
<script src="/WebResource.axd?d=x2nkrMJGXkMELz33nwnakPMYMZwQliPogleR8Jncs5Te0dqLYv8NHCY2aOdJRHcrcyPcCWkHq3sGXU9sQI23Mi-gbnQx3JHNM8eFN6fzaH81&amp;t=634773918900000000" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function WebForm_OnSubmit() {
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
return true;
}
//]]>
</script>

<div class="aspNetHidden">

	<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="jVdE4WNNUAUuymSBmzdWD9mWqMtaz0DvlwJDVYwkSSOmbtxQsCQlGyVpTXa7DcC+uCzC6RCWjZqydlArQJirfA0mKUUv4PsE3B/mHvJprgzml5paTylr34Ify2fBAbUqMf9yP38l1+Lw2+i2ENj3fzXegbsLWvYESaptRQ7AQ3QZeV8s/Rt/IUA5oQnoAj10zqXHXPDaCXznQ/Q3NV62s6D6kAXAwOus1VS7FhB+3JB64RJ8mldp5SSMk3+tlF9W" />
</div>
    <div class="auto-style1">
    
        <div class="auto-style4">
    
        <strong><span class="auto-style5">Transfering Flate</span><br />
        </strong>
        </div>
        <table class="auto-style2" cellpadding="5">
            <tr>
                <td class="auto-style6">Flat No</td>
                <td> <input name="TextBoxFN" type="text" id="TextBoxFN" />
                    <span data-val-controltovalidate="TextBoxFN" data-val-errormessage="Mandatory" id="RequiredFieldValidator1" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="color:Red;visibility:hidden;">Mandatory</span>
                </td>
            </tr>
            <tr>
                <td class="auto-style6">From</td>
                <td> <input name="TextBoxF" type="text" id="TextBoxF" />
                    <input type="submit" name="Button3" value="Get Owner&#39;s Details" id="Button3" />
                </td>
            </tr>
            <tr>
                <td class="auto-style6">Joining Date</td>
                <td> <input name="TextBoxJ" type="text" id="TextBoxJ" />
                </td>
            </tr>
            <tr>
                <td class="auto-style6">Leaving Date</td>
                <td> <input name="TextBoxLD" type="text" id="TextBoxLD" onclick="SetDate()" />
                   
                </td>
            </tr>
            <tr>
                <td class="auto-style6">TO{Initial Name}</td>
                <td> <input name="TextBoxT" type="text" id="TextBoxT" />
                    <span data-val-controltovalidate="TextBoxT" data-val-errormessage="Mandatory" id="RequiredFieldValidator3" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="color:Red;visibility:hidden;">Mandatory</span>
                </td>
            </tr>
            <tr>
                <td class="auto-style3" colspan="2">
                
                    <input type="submit" name="Button2" value="Update Existing Member Details" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;Button2&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="Button2" style="text-align: center" />
                    <br />
                    <br />
            <a id="HyperLink1" href="webform1.aspx">Go To Menu</a>
                </td>
                <td> &nbsp;</td>
            </tr>
        </table>
    
    </div>
    </form>

     
  
    
</body>
</html>

Open in new window

Julian HansenCommented:
Your javascript code is before the inclusion of the jquery library
Move your script to before the closing </body> tag and make sure that inclusion of the jQuery library comes BEFORE the code.

Moving this code AFTER jquery include.
<script type="text/javascript">
        function SetDate() {
            var date = new Date();

            var day = date.getDate();
            var month = date.getMonth() + 1;
            var year = date.getFullYear();

            if (month < 10) month = "0" + month;
            if (day < 10) day = "0" + day;

            var today = day + "/" + month + "/" + year;


            document.getElementById('TextBoxLD').value = today;
        }
    

        $(function () {
            $('#TextBoxLD').change(function () {
               //This function call on text change.             
               // Check if the joindate is 
                if (new Date($('#TextBoxJ').val()) > new Date($(this).val())) {
                alert('Join Date must preceed Leave Date');
                return false;
                }
               });
               });
</script>

Open in new window

Sukesh ShuklaAuthor Commented:
I just moved my Script at the end and it worked....

But where m i using the jquery library here in my code
Julian HansenCommented:
wherever you have a $()

19:  $(function () {
20:  $('#TextBoxLD').change(function () {
23: if (new Date($('#TextBoxJ').val()) > new Date($(this).val()))
Sukesh ShuklaAuthor Commented:
Thanks Julian.....:)
Sukesh ShuklaAuthor Commented:
I'm attatching one more rendered html , here also the setage function and the function to keep a check on joining date and leaving date is not working..Please help

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>

</title>
    <style type="text/css">
        .auto-style1 {
            text-align: center;
        }
        .auto-style9 {
            width: 341px;
            text-align: center;
        }
        .auto-style34 {
            width: 168px;
        }
        .auto-style10 {
            width: 341px;
            height: 26px;
            text-align: center;
        }
        .auto-style35 {
            height: 26px;
            width: 168px;
        }
        .auto-style11 {
            height: 26px;
        }
        .auto-style24 {
            color: #FF0000;
        }
        .auto-style16 {
            width: 341px;
            text-align: center;
            height: 23px;
        }
        .auto-style36 {
            width: 168px;
            height: 23px;
        }
        .auto-style13 {
            height: 23px;
        }
        
        .auto-style8 {
            width: 100%;
            background-color: #CCFFFF;
        }
        </style>
</head>
    
    
<body style="background-color: #CCFFCC">
    <form method="post" action="WebForm4.aspx?fnum=106&amp;fname=www&amp;ldate=23%2f10%2f2016" onsubmit="javascript:return WebForm_OnSubmit();" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="WTs7n9e/QLv/nZSG1rvA4btV3wZE5tRnnLACvV6K50lH8TXfu9dKALnK0nI02grsUnz3MBleBVFy9sh19L3Ep27fQRugtFXOMD1kyVaSCjw=" />
</div>

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>


<script src="/WebResource.axd?d=pynGkmcFUV13He1Qd6_TZCErUIiy0FccU42WH3R0u--CN1Jpl8tXLOXbLTNp_FIXJfC4VDiTZJY1l2ou5pl0dw2&amp;t=634773918900000000" type="text/javascript"></script>


<script src="/Scripts/jquery-1.7.1.js" type="text/javascript"></script>
<script src="/WebResource.axd?d=x2nkrMJGXkMELz33nwnakPMYMZwQliPogleR8Jncs5Te0dqLYv8NHCY2aOdJRHcrcyPcCWkHq3sGXU9sQI23Mi-gbnQx3JHNM8eFN6fzaH81&amp;t=634773918900000000" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function WebForm_OnSubmit() {
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
return true;
}
//]]>
</script>

<div class="aspNetHidden">

	<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="LHmoBBD8k4J8OX7slxzavbb9p0G7Jmlhyf3nW6OsAChtg8LXFEOLp1wjN9eg3y5+izLTB7cWyBYjghOX6/cqZaGLDdZbGq2Ut+RddscBb/7IjEB5fHjuhDPuv/YLTd7O+oY+qAZ3kR4PtlQgYpWh/Q+yaL/cmDRE/mfpVrN42RlhkP3516DhBBy8tDLLMYEekGStfAC+/9pyX0zVgTw+o7wM6jvTn4ufji6W71UZeid2U9RszHtqO+h+SVvvau283NdReSyvYY4mFhvuPJRmvW5khoFM1MBbg6GxCYxxSaN6drN22iHgWpYqqtHNmrEQOMAl/CkN+FmmTEXPjvkhI07tAfoR8+NGt7/K3ZrNZixrIaMF7dsnZfQIc19ZkqT9JAcogX2tInDG6+NqTIzc6MumIsGHbsTc8VfS7muEUyPHhIqtHdXJL/cClaUXWowPX4vlmoGOlY+tGMZysinp7vqSmmAsnWUfh6sD6jaoFKcu9E7dqgANF4vvXzoK9WhaSE/1DcZ8mgL4ctRxifTBsYtucv8mDSJAokvjKMHsvG5dnBUW4V4exBrC1aiS2Kmh" />
</div>


        <div class="auto-style1">
            Enter New Primary Member Details<br />
            <br />
            <br />
         <table class="auto-style8" cellpadding ="5px">
             <tr>
                 <td class="auto-style9">
                     <input type="hidden" name="HiddenFieldLD" id="HiddenFieldLD" value="23/10/2016" />
                 </td>
                 </tr>
             <tr>
                 <td class="auto-style9">Middle_Name</td>
                 <td class="auto-style34">
                     <input name="TextBoxMN" type="text" id="TextBoxMN" />
                 </td>
                 <td>
                     &nbsp;</td>
             </tr>
             <tr>
                 <td class="auto-style9">Last_Name</td>
                 <td class="auto-style34">
                     <input name="TextBoxLN" type="text" id="TextBoxLN" />
                 </td>
                 <td>
                     <span data-val-controltovalidate="TextBoxLN" data-val-errormessage="Last Name is Required" id="RequiredFieldValidator16" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="color:Red;visibility:hidden;">Last Name is Required</span>
                     <br />
                 </td>
             </tr>
             <tr>
                 <td class="auto-style9">Mobile Number</td>
                 <td class="auto-style34">
                     <input name="TextBoxMO" type="text" id="TextBoxMO" />
                 </td>
                 <td>
                     <span data-val-controltovalidate="TextBoxMO" data-val-errormessage="Mobile Number is Required" id="RequiredFieldValidator4" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="color:Red;visibility:hidden;">Mobile Number is Required</span>
                     <br />
                 </td>
             </tr>
            <tr>
                <td class="auto-style10">Email</td>
                <td class="auto-style35">
                    <input name="TextBoxE" type="text" id="TextBoxE" />
                </td>
                <td class="auto-style11">
                    <span data-val-controltovalidate="TextBoxE" data-val-focusOnError="t" data-val-errormessage="Invalid Email" id="RegularExpressionValidator1" data-val="true" data-val-evaluationfunction="RegularExpressionValidatorEvaluateIsValid" data-val-validationexpression="\w+([-+.&#39;]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" style="color:Red;visibility:hidden;">Invalid Email</span>
                </td>
            </tr>
            <tr>
                <td class="auto-style10">Date Of Birth</td>
                <td class="auto-style35">
                    <input name="TextBoxDOB" type="text" id="TextBoxDOB" class="manual" />
                </td>
                
                <td>
                    <span class="auto-style24">(mm/dd/yyyy)</span>
                </td>
                
            </tr>
            <tr>
                <td class="auto-style9">Age</td>
                <td class="auto-style34">
                    <input name="TextBoxA" type="text" id="TextBoxA" />
                </td>
                <td>
                     <span data-val-controltovalidate="TextBoxA" data-val-errormessage="Age is required" id="RequiredFieldValidator2" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="color:Red;visibility:hidden;">Age is required</span>
                 </td>
            </tr>
             <tr>
                 <td class="auto-style16">Educational Qualification</td>
                 <td class="auto-style36">
                     <input name="TextBoxEQ" type="text" id="TextBoxEQ" />
                 </td>
                 <td class="auto-style13"></td>
             </tr>
             <tr>
                 <td class="auto-style9">Office Address</td>
                 <td class="auto-style34">
                     <textarea name="TextBoxOA" rows="2" cols="20" id="TextBoxOA">
</textarea>
                 </td>
             </tr>
             <tr>
                 <td class="auto-style9">Native Address</td>
                 <td class="auto-style34">
                     <input name="TextBoxNA" type="text" id="TextBoxNA" />
                 </td>
                 <td>
                     <span data-val-controltovalidate="TextBoxNA" data-val-errormessage="Native Address is required" id="RequiredFieldValidator5" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="color:Red;visibility:hidden;">Native Address is required</span>
                 </td>
             </tr>
             <tr>
                 <td class="auto-style9">PAN Card Number</td>
                 <td class="auto-style34">
                     <input name="TextBoxPCN" type="text" id="TextBoxPCN" />
                 </td>
                 <td>
                     <span data-val-controltovalidate="TextBoxPCN" data-val-errormessage="PAN Card No Is Required" id="RequiredFieldValidator13" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="color:Red;visibility:hidden;">PAN Card No Is Required</span>
                 </td>
             </tr>
             <tr>
                 <td class="auto-style9">Aadhar Card Number</td>
                 <td class="auto-style34">
                     <input name="TextBoxACN" type="text" id="TextBoxACN" />
                 </td>
                 <td>
                     <span data-val-controltovalidate="TextBoxACN" data-val-errormessage="Aadhar number is Required" id="RequiredFieldValidator14" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="color:Red;visibility:hidden;">Aadhar number is Required</span>
                 </td>
             </tr>
             <tr>
                 <td class="auto-style9">Religion</td>
                 <td class="auto-style34">
                     <input name="TextBoxR" type="text" id="TextBoxR" />
                 </td>
                 <td>
                     <span data-val-controltovalidate="TextBoxR" data-val-errormessage="Religion is Mandatory" id="RequiredFieldValidator15" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="color:Red;visibility:hidden;">Religion is Mandatory</span>
                 </td>
             </tr>
             <tr>
                 <td class="auto-style16">Business/Job</td>
                 <td class="auto-style36">
                     <table id="RadioButtonListBJ">
	<tr>
		<td><input id="RadioButtonListBJ_0" type="radio" name="RadioButtonListBJ" value="Business" /><label for="RadioButtonListBJ_0">Business</label></td><td><input id="RadioButtonListBJ_1" type="radio" name="RadioButtonListBJ" value="Job" /><label for="RadioButtonListBJ_1">Job</label></td>
	</tr>
</table>
                 </td>
                 <td class="auto-style13">
                     &nbsp;</td>
             </tr>
             <tr>
                 <td class="auto-style16">Married/UnMarried</td>
                 <td class="auto-style36">
                     <table id="RadioButtonListMU">
	<tr>
		<td><input id="RadioButtonListMU_0" type="radio" name="RadioButtonListMU" value="Married" /><label for="RadioButtonListMU_0">Married</label></td><td><input id="RadioButtonListMU_1" type="radio" name="RadioButtonListMU" value="Unmarried" /><label for="RadioButtonListMU_1">Unmarried</label></td>
	</tr>
</table>
                 </td>
                 <td class="auto-style13">
                     &nbsp;</td>
             </tr>
            <tr>
                <td class="auto-style9">No Of Members</td>
                <td class="auto-style34">
                    <input name="TextBoxNOM" type="text" id="TextBoxNOM" />
                </td>
                <td>
                    <span data-val-controltovalidate="TextBoxNOM" data-val-errormessage="Number Of Members is Required" id="RequiredFieldValidator7" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="color:Red;visibility:hidden;">Number Of Members is Required</span>
                    <br />
                    <span data-val-controltovalidate="TextBoxNOM" data-val-errormessage="Only Numbers are allowed" id="RegularExpressionValidator5" data-val="true" data-val-evaluationfunction="RegularExpressionValidatorEvaluateIsValid" data-val-validationexpression="^\d+$" style="color:Red;visibility:hidden;">Only Numbers are allowed</span>
                </td>
            </tr>
            <tr>
                <td class="auto-style9">Joining Date</td>
                <td class="auto-style34">
                    <input name="TextBoxJ" type="text" id="TextBoxJ" onclick="SetDate()" />
                </td>
                <td>
                    <span data-val-controltovalidate="TextBoxJ" data-val-errormessage="Date is Required" id="RequiredFieldValidator18" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="color:Red;visibility:hidden;">Date is Required</span>
                </td>
            </tr>
        </table>
            <br />
            <br />


        <input type="submit" name="Button1" value="Update Dtabase" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;Button1&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="Button1" style="height:62px;width:323px;" />
        
            <br />
            <br />
            <br />
            <br />
            <br />
        <a id="HyperLink1" href="webform1.aspx">Go To Menu</a>
        </div>
        
    </form>

    <script>
        function SetDate() {
            var date = new Date();

            var day = date.getDate();
            var month = date.getMonth() + 1;
            var year = date.getFullYear();

            if (month < 10) month = "0" + month;
            if (day < 10) day = "0" + day;

            var today = day + "/" + month + "/" + year;


            document.getElementById('TextBoxJ').value = today;
        }


       
        function setAge(d) {
            var age = moment().diff(d, 'years');
            $('#TextBoxA').val(age);
        }

        $(function () {
            $('.manual').change(function () {
                setAge(moment($(this).val()));
            });
        });
</script>
    <script>
       $(function () {
           $('#TextBoxJ').change(function () {
               //This function call on text change.             
                // Check if the joindate is 
                if (new Date($('#HiddenFieldLD').val()) > new Date($(this).val())) {
                    alert('Invalid Date');
                    return false;
                }
 });
       });
</script>
</body>
</html>

Open in new window

Julian HansenCommented:
I am not sure what you mean by "not working" you need to tell me what the problem is.


Not working could mean several things
1. Nothing happens when you enter an invalid date
2. The wrong thing happens when you enter an invalid date

When I load that page and change the Joining date I get an Invalid Date message so that rules out #1

The problem I see is that your date formats are wrong. Your date formats should be either
UTC
yyyy-mm-dd

OR US
mm/dd/yyyy

Note the first uses '-' as separators the second uses '/'

dd/mm/yyyy is just going to result in an invalid date because JavaScript is going to interpret that as a US date and 23/10/2015 is going to come out as 10 Nov 2017
Sukesh ShuklaAuthor Commented:
Yes i got your point......Julian
Is there a way i could call this jquery function  implemented on TextBoxJ on a button click ie named as Update database......
Julian HansenCommented:
We are branching into new question territory here.

Are you asking about validating the date on submit?
Sukesh ShuklaAuthor Commented:
Yes
Julian HansenCommented:
Change
$(function () {
           $('#TextBoxJ').change(function () {
               //This function call on text change.             
                // Check if the joindate is 
                if (new Date($('#HiddenFieldLD').val()) > new Date($(this).val())) {
                    alert('Invalid Date');
                    return false;
                }
 });
       });

Open in new window

To
$(function () {
  $('#TextBoxJ').change(function () {
     validateDate();
   });
   $('form').submit(function() {
       return validateDate();
   });      
});
function validateDate()
{
  //This function call on text change.             
  // Check if the joindate is 
  if (new Date($('#HiddenFieldLD').val()) > new Date($('#TextBoxJ').val())) {
    alert('Invalid Date');
    return false;
  }
  return true;
 }

Open in new window

Sukesh ShuklaAuthor Commented:
Thank you Julian ..... :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
AJAX

From novice to tech pro — start learning today.