如何对控件使用JavaScript验证和asp.net验证 [英] How to use the both JavaScript validation and asp.net validation for a control

查看:70
本文介绍了如何对控件使用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 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


这篇关于如何对控件使用JavaScript验证和asp.net验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆