如何对控件使用JavaScript验证和asp.net验证

问题描述:

function myFunction() {
    var DOB = document.getElementById("<%= DOB_Day.ClientID %>").value;
    var DOBsubstring = DOB.substring(6, 10);
    var DOBconv = parseInt(DOBsubstring);
    var DOBYear = DOBconv + 13;
    var tenth = document.getElementById("<%= TenYear.ClientID %>").value;
    var twelth = document.getElementById("<%= TwelveYear.ClientID %>").value;
    var ug = document.getElementById("<%= GradYear.ClientID %>").value;
    var pg = document.getElementById("<%= PostGradYear.ClientID %>").value;
    var nctvt = document.getElementById("<%= TextBox1.ClientID %>").value;

    if (DOBYear < tenth) {
      if (twelth != "" && tenth != "") {
          if (twelth <= tenth) {
              alert("Twelth Passing year Should be Greater then Tenth Passing Year !");
              return false;
          }
      }
    }
    else {
      alert("Tenth Passing year Should be Greater then 13 year from Birth !");
      return false;
    }
    if (ug != "" && twelth != "") {
      if (ug <= twelth) {
          alert("UG Passing year Should be Greater then Twelth Passing Year !");
          return false;
      }
    }
    if (ug != "" && tenth != "") {
      if (ug <= tenth) {
          alert("UG Passing year Should be Greater then Tenth Passing Year !");
          return false;
      }
    }
    if (pg != "" && tenth != "") {
      if (pg <= tenth) {
          alert("PG Passing year Should be Greater then Tenth passing year !");
          return false;
      }
    }
    if (pg != "" && ug != "") {
      if (pg <= ug) {
          alert("PG Passing year Should be Greater then UG Passing Year !");
          return false;
      }
    }
    if (nctvt != "" && tenth != "") {
      if (nctvt <= tenth) {
          alert("NCTVT/NAC Passing year Should be Greater then Tenth Passing Year !");
          return false;
      }
    }
}



我为 DOB_Day $ c $设置所需的字段验证控件c>, TenYear TwelveYear TwelveYear PostGradYear 。当我单击提交按钮 JavaScript 验证工作但Asp.Net RequiredField 验证控件无效....



回答我!


Where i put required field validation control for DOB_Day, TenYear, TwelveYear, TwelveYear, PostGradYear. When i click submit button JavaScript validation working but Asp.Net RequiredField Validation control is not working....

Answer Me !

因为你的返回错误代码每个循环,服务器端验证都被阻止..

使用客户端服务器端验证,代码服务器端不需要验证,我认为......
Because of your "return false" code in each loop, Server Side Validation is Prevented..
Use either Client Side or Server Side Validation, for your code Server side Validation is not needed, I think...


引用:

if(DOBYear< tenth){

if(twelth!=&& tenth!=){

if(twelth< = tennth){

alert( Twelth Passing year应该大于第十个传递年份!;

返回false;

}

}

}

else {

alert(第十个过去的一年应该比出生时更长13年!);

返回false;

}

if (DOBYear < tenth) {
if (twelth != "" && tenth != "") {
if (twelth <= tenth) {
alert("Twelth Passing year Should be Greater then Tenth Passing Year !");
return false;
}
}
}
else {
alert("Tenth Passing year Should be Greater then 13 year from Birth !");
return false;
}





上面提到你的验证码不允许服务器方验证,因为您的代码路径返回false,因此它将停止服务器端验证。您可以使用客户端验证或服务器端验证。如果您有任何特殊情况意味着仍然要使用两个验证,请将return语句修改为返回true



谢谢,

-RG



The above mentioned your validation code will not allow server side validation, because your code paths returning false so it will stop server side validation.You can use either client side validations or server side validation.If you have any special scenario means still you want to use both validations modify your return statement to "return true"

Thanks,
-RG