即使存在值

时间:2016-06-07 18:55:25

标签: asp.net validation

我有一个Page水果,其中包含UpdatePanel P1和ModalWIndow(更新面板之外)。我有一个Page Apple,其中包含UpdatePanel P2。 ModalWindow水果上的Page会根据需要添加Page Apple。

现在,在Apple Page中 我有一个GridView EditItemTemplateFooterItemtemplate,可以说5列。它们都有RegularExpressionValidatorRequiredFieldValidtor,每个ValidationGrou p分隔。对于EditItemTemplate来说,一切都是关键。 对于FooterItemTemplate,即使满足所有验证,该按钮也不会进行回发。 页脚模板对于感兴趣的列看起来像这样

<FooterTemplate>
     <asp:TextBox ID="vendorAdd" runat="server"  Width="95%"/>
     <asp:RegularExpressionValidator ID="RegularExpressionValidator66" ControlToValidate="vendorAdd" ValidationGroup="AddValidation"
                                        ValidationExpression="\w*" runat="server" ErrorMessage="Invalid VendorName" />
     <asp:RequiredFieldValidator id = "RegularExpressionValidator67" ValidationGroup="AddValidation" ControlToValidate="vendorAdd"
                                        runat="server" ErrorMessage="VendorName Required" />
</FooterTemplate>

没有消息称此失败。我删除了其他页脚列上的所有其他验证,而不是上面显示的。我在按钮上添加了停止验证。在服务器端添加了这个

Page.Validate("AddValidation");
var b = Page.IsValid;

var notValidValidators = Page.Validators.Cast<IValidator>().Where(v => !v.IsValid);`

调试器中notValidValidator表示RequiredFieldValidator无效。我不明白为什么,但我有一个价值,前端没有消息。

Apple页面上的

更新面板完整代码位于

之下
  <asp:UpdatePanel ID="ackPanel" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:GridView ID="ackedItems" runat="server" Width="720" Visible="true" DataKeyNames="AckId" RowStyle-Height="10px"
                        AutoGenerateColumns="False" BorderStyle="Dotted" BorderWidth="1px" CellPadding="2"
                        BackColor="White" BorderColor="#CCCCCC" HorizontalAlign="Left" AllowPaging="false"
                        ShowFooter="true" OnRowUpdating="AckedItems_RowUpdating" OnRowDeleting="AckedItems_RowDeleting"
                        OnRowEditing="AckedItems_RowEditing" OnRowCommand="AckedItems_RowCommand" OnRowDataBound="AckedItems_RowDataBound">
                        <RowStyle ForeColor="#000066" Font-Size="8pt" />
                        <HeaderStyle ForeColor="#336699" Font-Size="8pt" CssClass="GridViewHeader" Height="20px" />
                        <AlternatingRowStyle CssClass="GridViewAltStyle" />
                        <Columns >
                            <asp:BoundField DataField="AckId" ReadOnly="true" Visible="false" />
                            <asp:TemplateField HeaderText="Vendor" HeaderStyle-Width="10%">
                                <ItemTemplate>
                                    <asp:Label ID="vendor" runat="server" Text='<%# Bind("VendorName") %>' Width="95%"/>
                                </ItemTemplate>
                                <EditItemTemplate >
                                    <asp:TextBox ID="vendorEdit" runat="server" Text='<%# Bind("VendorName") %>' Width="95%"/>
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="vendorEdit" ValidationGroup="EditValidation"
                                        ValidationExpression="\w*" runat="server" ErrorMessage="Invalid VendorName" />
                                    <asp:RequiredFieldValidator id = "Ab"  ValidationGroup="EditValidation" ControlToValidate="vendorEdit"
                                        runat="server" ErrorMessage="VendorName Required" />
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="vendorAdd" runat="server"  Width="95%"/>
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator66" ControlToValidate="vendorAdd" ValidationGroup="AddValidation"
                                    ValidationExpression="\w*" runat="server" ErrorMessage="Invalid VendorName" />
                                    <asp:RequiredFieldValidator id = "RegularExpressionValidator67" ValidationGroup="AddValidation" ControlToValidate="vendorAdd"
                                    runat="server" ErrorMessage="VendorName Required" />
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Amount" HeaderStyle-Width="10px">
                                <ItemTemplate>
                                    <asp:Label ID="amount" DataFormatString = "{0:C2}" runat="server" Text='<%# Bind("Amount") %>'  Width="95%" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="amountEdit" runat="server" Text='<%# Bind("Amount") %>'  Width="95%"/>
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator3" ControlToValidate="amountEdit" ValidationGroup="EditValidation"
                                        ValidationExpression="\d*(\.\d*)?" runat="server" ErrorMessage="Invalid Amount" />
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" ValidationGroup="EditValidation" ControlToValidate="amountEdit"
                                        runat="server" ErrorMessage="Amount Required" />
                                </EditItemTemplate>
                                <FooterTemplate >
                                    <asp:TextBox ID="amountAdd" runat="server"  
                                     Width="95%" />
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator4" ControlToValidate="amountAdd" ValidationGroup="AddValidation"
                                        ValidationExpression="\d*(\.\d*)?" runat="server" ErrorMessage="Invalid Amount" />
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Type">
                                <ItemTemplate>
                                    <asp:Label ID="type" runat="server" Text='<%# Bind("Type") %>' Width="95%" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="typeEdit" runat="server" Text='<%# Bind("Type") %>'  Width="95%" />
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator5" ControlToValidate="typeEdit" ValidationGroup="EditValidation"
                                        ValidationExpression="\w*" runat="server" ErrorMessage="Invalid Type" />
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" ValidationGroup="EditValidation" ControlToValidate="typeEdit"
                                        runat="server" ErrorMessage="Type Required" />
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="typeAdd" runat="server"  Width="95%" />
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator2" ControlToValidate="typeAdd"
                                        ValidationGroup="AddValidation" ValidationExpression="\w*" runat="server" ErrorMessage="Invalid Type" />
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:BoundField DataField="ProgNum" ReadOnly="true" HeaderText="ProgNum" ControlStyle-Width="95%" />
                           <asp:TemplateField HeaderText="AckDate">
                              <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%#Convert.ToDateTime(Eval("AckDate")).ToString("MM/dd/yyyy") %>' Width="95%"/>
                             </ItemTemplate>
                             </asp:TemplateField>
                            <asp:TemplateField HeaderText="Notes" >
                                <ItemTemplate>
                                    <asp:Label ID="notes" runat="server" Text='<%# Bind("Notes") %>' Width="95%" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="notesEdit" Text='<%# Bind("Notes") %>' runat="server"  Width="95%"/>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="notesAdd" runat="server" Width="95
                                    %" />
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="ActivityDate">
                                <ItemTemplate>
                                    <asp:Label ID="activityDate" runat="server" Text='<%#Convert.ToDateTime(Eval("activityDate")).ToString("MM/dd/yyyy") %>' Width="95%" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="activityDateEdit" Text='<%#Convert.ToDateTime(Eval("activityDate")).ToString("MM/dd/yyyy") %>' runat="server"  CssClass="date" Width="95%" />
                                    <asp:CompareValidator ID="CompareValidator1" runat="server" Type="Date" Operator="DataTypeCheck" ValidationGroup="EditValidation"
                                        ControlToValidate="activityDateEdit" ErrorMessage="Invalid Date" />
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator7" ValidationGroup="EditValidation" ControlToValidate="activityDateEdit"
                                        runat="server" ErrorMessage="Date Required" />
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="activityDateAdd" runat="server" CssClass="date"  Width="95%"/>
                                    <asp:CompareValidator ID="CompareValidator2" runat="server" Type="Date" Operator="DataTypeCheck" ValidationGroup="AddValidation"
                                        ControlToValidate="activityDateAdd" ErrorMessage="Invalid Date" />
                                           </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="IsVoid">
                                <ItemTemplate>
                                    <asp:CheckBox ID="isVoid" runat="server" Checked='<%# Eval("IsVoid") %>' Width="95%" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:CheckBox ID="isVoidEdit" runat="server" Checked='<%# Eval("IsVoid") %>'  Width="95%" />
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:CheckBox ID="isVoidAdd" runat="server" Width="95%"  />
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="VoidReason">
                                <ItemTemplate>
                                    <asp:Label ID="voidReason" runat="server" Text='<%# Bind("VoidReason") %>' Width="95%" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:DropDownList ID="voidReasonEdit" runat="server" Width="95%"  />
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:DropDownList ID="voidReasonAdd" runat="server" Width="95%" />
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>
                                <ItemStyle HorizontalAlign="Center" />
                                <ItemTemplate>
                                    <asp:LinkButton ID="lbEdit" runat="server" CausesValidation="false" CommandName="Edit"
                                        Text="<img border=0 src=../Theme/Main/Images/edit.gif alt=Edit>" />&nbsp;
                                    <asp:LinkButton ID="lbDelete" runat="server" CausesValidation="false" CommandName="Delete"
                                        OnClientClick="if(!confirm('Do You Really want to Delete this Order Item?')) return false;"
                                        Text="<img border=0 src=../Theme/Main/Images/delete.gif alt=Delete>" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:LinkButton ID="lbAdd" runat="server" CausesValidation="true" CommandName="Update"
                                        ValidationGroup="EditValidation" Text="<img border=0 src=../Theme/Main/Images/check.gif alt=Update>" />&nbsp;
                                    <asp:LinkButton ID="lbDelete" runat="server" CausesValidation="false" CommandName="Cancel"
                                        Text="<img border=0 src=../Theme/Main/Images/delete.gif alt=Cancel>" />
                                </EditItemTemplate>
                                <FooterStyle HorizontalAlign="Center" VerticalAlign="Top" />
                                <FooterTemplate>
                                    <asp:LinkButton ID="lbAdd" runat="server" CausesValidation="false" CommandName="Add"
                                        ValidationGroup="AddValidation" Text="<img border=0 src=../Theme/Main/Images/check.gif alt=Add>" />&nbsp;
                                    <asp:LinkButton ID="lbDelete" runat="server" CausesValidation="false" CommandName="Cancel"
                                        Text="<img border=0 src=../Theme/Main/Images/delete.gif alt=Cancel>" />
                                </FooterTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <EmptyDataTemplate>
                            <asp:TextBox ID="vendorEdit" runat="server" Text='<%# Bind("Vendor") %>' CssClass="InputTextBox"
                                Width="100px" />
                        </EmptyDataTemplate>
                    </asp:GridView>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="lbEdit" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>

0 个答案:

没有答案