asp.net:验证失败后禁用回发 [英] asp.net: Postback disabled after validation failed

查看:86
本文介绍了asp.net:验证失败后禁用回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

验证失败后,我的控件(下拉列表或按钮)出现问题,应导致新的回发.我会尽力解释清楚...

After validation failed, I have a problem with controls (dropdownlist or button) that should cause a new postback. I will try to explain it clearly...

我的页面的目的是在数据库中保存5个日期.该页面具有以下控件:

The purpose of my page is to save fives dates in a database. The page has the following controls:

  • 五个文本框,每个文本框包含一个日期
  • 一个重置按钮(CausesValidation = false),用于在5个文本框之一中恢复默认日期
  • 预定义模板的下拉列表(AutoPostback = true,CaessValidation = false)将5个日期应用于5个文本框
  • 将日期保存到数据库的按钮

可以手动编辑文本框.因此,当我单击保存"按钮时,如果日期格式无效,则验证将失败并且保存将中止.问题就在那之后.如果单击重置"按钮或在下拉列表中选择一个项目,则不会触发回发.如果我再试一次,则可以.有没有一种方法可以使它在第一次验证失败后第一次运行?更改下拉列表中的选择时,我尝试在客户端上停用验证,但仍不会发生回发.

The textboxes can be edited manually. So, when I click the Save button, if the format of the dates is not valid, the validation fails and the save is aborted. The problem is just after that. If I click on the Reset button or select an item in the dropdownlist, the postback is not triggered. If I try again, then it works. Is there a way to make it work the first time after the first validation failed? I tried deactivating the validation on the client-side when changing the selection in the dropdownlist but the postback still does not occur.

这是代码的相关部分:

<asp:DropDownList ID="cboScheduleTemplates" runat="server" AutoPostBack="true" CausesValidation="false" />
<asp:TextBox ID="txtDateDelivery1" runat="server" />
<asp:RegularExpressionValidator ID="revDateDelivery1" runat="server" Display="Dynamic" ValidationGroup="Schedule" ControlToValidate="txtDateDelivery1" Text="*" />
<asp:TextBox ID="txtDateYearbookQuantity" runat="server" />
<asp:RegularExpressionValidator ID="revDateYearbookQuantity" runat="server" Display="Dynamic" ValidationGroup="Schedule" ControlToValidate="txtDateYearbookQuantity" Text="*" />
<asp:TextBox ID="txtDateDelivery2" runat="server" />
<asp:RegularExpressionValidator ID="revDateDelivery2" runat="server" Display="Dynamic" ValidationGroup="Schedule" ControlToValidate="txtDateDelivery2" Text="*" />
<asp:TextBox ID="txtDatePersonalizations" runat="server" />
<asp:RegularExpressionValidator ID="revDatePersonalizations" runat="server" Display="Dynamic" ValidationGroup="Schedule" ControlToValidate="txtDatePersonalizations" Text="*" />
<asp:TextBox ID="txtDateDelivery3" runat="server" />
<asp:Button ID="btnSetDefaultDelivery3" runat="server" ValidationGroup="Schedule" CausesValidation="false" />
<asp:RegularExpressionValidator ID="revDateDelivery3" runat="server" Display="Dynamic" ValidationGroup="Schedule" ControlToValidate="txtDateDelivery3" Text="*" />
<asp:Button ID="btnSaveSchedule" runat="server" CssClass="btnAction" Text="Save" ValidationGroup="Schedule" />
<asp:ValidationSummary ID="validationSummarySchedule" runat="server" ValidationGroup="Schedule" DisplayMode="List" />

推荐答案

As suggested in this post, the problem comes from calls to Page_ClientValidate. So I wrapped the client function like this and the problem went away:


function DoPageClientValidate(validationGroupName) 
{
     var result = Page_ClientValidate(validationGroupName);
     Page_BlockSubmit = false;
     return result; 
}

这篇关于asp.net:验证失败后禁用回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆