我有以下文本框控件;
<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/