验证失败后,我的控件(下拉列表或按钮)出现问题会导致新的回发。我会尽力解释清楚......
我的页面的目的是在数据库中保存五个日期。该页面包含以下控件:
可以手动编辑文本框。因此,当我单击“保存”按钮时,如果日期格式无效,则验证失败并中止保存。问题就在那之后。如果我单击“重置”按钮或在下拉列表中选择一个项目,则不会触发回发。如果我再试一次,那就行了。有没有办法让它在第一次验证失败后第一次工作?我在更改下拉列表中的选择时尝试在客户端停用验证,但仍未发生回发。
以下是代码的相关部分:
<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" />
答案 0 :(得分:4)
正如this post中所述,问题来自对Page_ClientValidate的调用。所以我把这样的客户端函数包装好了,问题就消失了:
function DoPageClientValidate(validationGroupName) { var result = Page_ClientValidate(validationGroupName); Page_BlockSubmit = false; return result; }