ASP.NET文本框客户端验证没有回发 [英] ASP.NET Textbox client side validation with out postback
本文介绍了ASP.NET文本框客户端验证没有回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function Validation()
{
var txtDob = document.getElementById("<%=txtDob.ClientID%>").value;
var returnVal = "true";
if (txtDob != "") {
if (isDate(txtDob) == false)
$("#<%=txtDob.ClientID%>").addClass("txtValidate");
else
$("#<%=txtDob.ClientID%>").removeClass("txtValidate");
}
if (returnVal == "true")
return true;
else
return false;
}
如果以上javascript函数返回true,那么我的服务器代码将执行....
if the above javascript function returns true only then my server code will execute ....
<asp:TextBox ID="txtDob" runat="server" AutoPostBack="true" onchange="rerurn Validation();" OnTextChanged="txtExample_TextChanged"></asp:TextBox>
代码背后
Code Behind
protected void txtExample_TextChanged(object sender, EventArgs e)
{
// If the client side function returns true then only this will execute..
}
推荐答案
( #<%= txtDob.ClientID%> )。addClass( txtValidate);
else
("#<%=txtDob.ClientID%>").addClass("txtValidate"); else
( #<%= txtDob.ClientID%>)。removeClass( txtValidate跨度>);
}
如果(returnVal == true)
return true ;
else
return false < /跨度>;
}
("#<%=txtDob.ClientID%>").removeClass("txtValidate"); } if (returnVal == "true") return true; else return false; }
如果以上javascript函数返回true,那么我的服务器代码将执行....
if the above javascript function returns true only then my server code will execute ....
<asp:TextBox ID="txtDob" runat="server" AutoPostBack="true" onchange="rerurn Validation();" OnTextChanged="txtExample_TextChanged"></asp:TextBox>
代码背后
Code Behind
protected void txtExample_TextChanged(object sender, EventArgs e)
{
// If the client side function returns true then only this will execute..
}
Hello Sumant,
在您的Javascript中,您没有更新变量的值returnvalue
。所以你的函数总是返回true,导致回发。
问候,
Hello Sumant,
In your Javascript you are not updating the value of variablereturnvalue
. So your function is always returning true resulting in a postback.
Regards,
这篇关于ASP.NET文本框客户端验证没有回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文