Reputation: 34177
I am trying to test for a textbox value.
If the value matches my criteria do a javascript function
ELSE
do textchanged event in code behind.
I have a jquery function that is triggered using javascript on change
JAVASCRIPT
function test() {
if ($('#<%= txt.ClientID%>').val() == '1') {
return false;
}
};
ASP.NET
<asp:TextBox ID="txt" runat="Server" AutoPostBack="true" onchange="test(this)" />
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.
THE MARKUP RENDERS AS
onchange="test(this);setTimeout('__doPostBack(\'ctl00$ctl00$ctl00$Master$Content$txt\',\'\')', 0)"
QUESTION
Upvotes: 1
Views: 1709
Reputation: 96
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;" />
Upvotes: 2