[英]How to prevent execution of serverside function using javascript?
I am trying to test for a textbox value. 我正在尝试测试文本框值。
If the value matches my criteria do a javascript function 如果值符合我的标准,请执行javascript函数
ELSE 其他
do textchanged event in code behind. 在后面的代码中执行textchanged事件。
I have a jquery function that is triggered using javascript on change 我有一个jQuery函数,在更改时使用javascript触发
JAVASCRIPT JAVASCRIPT
function test() {
if ($('#<%= txt.ClientID%>').val() == '1') {
return false;
}
};
ASP.NET ASP.NET
<asp:TextBox ID="txt" runat="Server" AutoPostBack="true" onchange="test(this)" />
VB.NET VB.NET
Protected Sub txt_TextChanged(sender As Object, e As EventArgs) Handles txt.TextChanged
...
End Sub
While debugging the function clearly returns false however the textchanged event still causes a postback. 在调试该函数时,显然会返回false,但是textchanged事件仍然会导致回发。
THE MARKUP RENDERS AS 标记渲染商
onchange="test(this);setTimeout('__doPostBack(\'ctl00$ctl00$ctl00$Master$Content$txt\',\'\')', 0)"
QUESTION 题
try to return false inline of textbox as below:- 尝试返回错误的文本框内联,如下所示:
function test() {
if ($('#<%= txt.ClientID%>').val() == '1') {
return false;
}
return true;
};
<asp:TextBox ID="txt" runat="Server" AutoPostBack="true" onchange="if(!test(this)) return false;" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.