c# - 如果验证错误则停止回发

标签 c# javascript jquery .net validation

我有以下文本框控件;

   <asp:TextBox ID="txtAmount" runat="server" AutoPostBack="true" Width="85px" class="validate[ERExpenseTypeDaterequired,custom[float]]"
                                OnTextChanged="txtAmount_TextChanged"   ></asp:TextBox>

这里,如果文本框中有任何值更改,txtAmount_TextChanged 将被调用,因为 AutoPostBack="true" 位于控件中。

因此,如果我们在文本框中输入非数字值,则使用 Jquery 从属性 Class 中触发验证错误,但从文本框中弹出的红色框不会停留超过 3 秒,它会在以下情况下消失:页面在 3 秒内回发,发生此回发只是因为存在 AutopostBack="true"

我无法执行Autopostback="false",因为我需要根据此文本框值的当场更改进行一些计算。

如果我这样做Autopostback="false",页面将不会回发并且错误消息将永远保留,但我无法对“txtAmount_TextChanged”事件进行任何计算,因为如果 Autopostback="false",则永远不会在 textchcange 上调用此事件。

那么,如果此文本框中存在任何验证错误,我该如何防止此回发?

最佳答案

function txtAmount_TextChanged(){
    //do validations here, Eg: validate if txtAmount is valid amount and "> 0"
   return false; //if somethings's wrong, else true

}

关于c# - 如果验证错误则停止回发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11931508/

相关文章:

javascript - 开源客户端购物车 - jQuery/Cookies

javascript - 如何像磁铁效果一样创建鼠标对 Div 的抵抗力

c# - Delphi 调用非托管 dll 工作正常,但 C# 不

c# - WININET.InternetConnect 在 Windows 8 中失败

javascript - FabricJS 圆显示半径

javascript - 错误 : <tspan> attribute dy: Expected length, "NaN"。 |错误 : <path> attribute d: Expected number, "M,0,0"。 |拉斐尔.js |轮子导航.js

c# - 表达树生成的IL是否经过优化?

c# - 如何将 DataTable 转换为 List<KeyValuePair<string, int>>

javascript - 使用多个版本的 RequireJS

javascript - Bootstrap Collapse.js 开关隐藏/显示菜单