即使禁用了验证器,RequiredFieldValidator也会在Server上进行验证(CausesValidation =“false”)

时间:2013-03-07 07:06:41

标签: c# asp.net

我将CausesValidation =“false”设置为我的取消按钮,但是当我单击取消按钮时,异常(箭头)显示页面加载后的几分之一秒。我尝试了多种方法来通过添加组名来禁用验证器和验证器的EnableClientScript属性= false,但这些无法帮助我解决问题。即使我检查了许多线程,但没有人给出解决方案。如果有任何身体遇到这个问题,请帮助我。

<form id="form1" runat="server">
<div class="AdminContent">
    <asp:Label ID="Label1" runat="server" CssClass="BreadcrumbActiveBig" Text="Group Membership" />
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <br />
    <br />
    <asp:HiddenField ID="HiddenFieldProfile" runat="server" />
    <asp:FormView DefaultMode="Edit" ID="FormView1" runat="server" DataSourceID="PermGroupObjectDataSource1"
        OnPreRender="FormView1_PreRender">
        <EditItemTemplate>
            <table>
                <tr>
                    <td align="left" colspan="3">
                        <asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save" Width="67px"
                            CssClass="ButtonS1" />
                        <asp:Button ID="btnCancel" runat="server" OnClick="btnCancel_Click" Text="Cancel"
                            CssClass="ButtonS1" CausesValidation="false" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="lblGrpName" runat="server" Text="Group Name:" Width="138px" />
                    </td>
                    <td>
                        <asp:TextBox ID="GroupNameTextBox" MaxLength="50" runat="server" Text='<%# Bind("GroupName") %>'
                            Width="337px" ReadOnly="false" />
                        <asp:RequiredFieldValidator ID="rqrgFldVldtr_GroupName" ControlToValidate="GroupNameTextBox"
                            Display="Dynamic" ErrorMessage="&lt;" meta:resourcekey="RequiredFieldValidator1Resource2"
                            runat="server"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="lblGrpDescr" runat="server" Text="Group Description:" Width="138px" />
                    </td>
                    <td>
                        <asp:TextBox ID="GroupDescrTextBox" MaxLength="255" runat="server" Text='<%# Bind("GroupDescr") %>'
                            Width="337px" ReadOnly="false" />
                    </td>
                </tr>
                <tr>
                    <asp:Panel ID="managedByPanel" runat="server" Visible="false">
                        <td>
                            <asp:Label ID="lblManagedByDescr" runat="server" Text="Managed by:" Width="138px" />
                        </td>
                        <td>
                            <asp:DropDownList ID="managedByDropDownList" runat="server">
                                <asp:ListItem Value="0" Text="Admin" />
                                <asp:ListItem Value="1" Text="AP Clerk admin &amp; Admin" />
                                <asp:ListItem Value="2" Text="POC admin &amp; Admin" />
                            </asp:DropDownList>
                        </td>
                    </asp:Panel>
                </tr>
                <tr>
                    <asp:Panel ID="lblFilterPanel" runat="server" Visible="false">
                        <td>
                            <asp:Label ID="LabelFilter" runat="server" Text="Exclude From Document Filter" Width="150px" />
                        </td>
                        <td>
                            <asp:CheckBox ID="chbExcludefromDocFilter" runat="server" Checked='<%# Bind("ExcludeFromUserFilter") %>' />
                        </td>
                    </asp:Panel>
                </tr>
                <tr>
                    <td valign="top">
                        <asp:Label ID="lblMembers" runat="server" Text="Members:" Width="80px" />
                    </td>
                    <td>
                        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                            <ContentTemplate>
                                <div>
                                    <asp:ListBox ID="lbxMembers" runat="server" Style="overflow: auto; width: 500px;
                                        height: 150px;" DataSourceID="MembersObjectDataSource1" DataTextField='ListName'
                                        DataValueField="UName" SelectionMode="Multiple" />
                                    <br />
                                    <asp:ObjectDataSource ID="MembersObjectDataSource1" runat="server" DataObjectTypeName="System.Collections.Generic.List`1[[Accenture.CSTPrague.eAPI.GroupMember, eAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"
                                        SelectMethod="FetchGroupMembers" TypeName="Accenture.CSTPrague.eAPI.WebDB_Perm"
                                        UpdateMethod="StoreGroupMembers">
                                        <SelectParameters>
                                            <asp:SessionParameter Name="o" SessionField="oPermGroup" Type="Object" />
                                        </SelectParameters>
                                    </asp:ObjectDataSource>
                                </div>
                                <asp:Button ID="btnDeleteSelected" runat="server" OnClick="btnDeleteSelected_Click"
                                    Text="Delete Selected" Width="106px" CssClass="ButtonS1" Style="margin: 4px 0px 8px 2px;" />
                            </ContentTemplate>
                            <Triggers>
                                <asp:AsyncPostBackTrigger ControlID="btnDeleteSelected" EventName="Click" />
                            </Triggers>
                        </asp:UpdatePanel>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="lblUserName" runat="server" Text="User name:" Width="141px" />
                    </td>
                    <td>
                        <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                            <ContentTemplate>
                                <asp:Panel ID="panel1" runat="server" DefaultButton="btnAdd">
                                    <table>
                                        <tr>
                                            <td valign="top">
                                                <accenture:lookupcontrol id="UserLookup" runat="server" lookupcommand="usr" maxlength="100"
                                                    validationgroup="addUser" disablevalidation="true" />
                                            </td>
                                            <td>
                                                <asp:CustomValidator ID="cuvUserName" runat="server" ValidationGroup="addUser" Display="Dynamic"
                                                    ErrorMessage="<" EnableClientScript="false" OnServerValidate="cuvUserName_ServerValidate"
                                                    ControlToValidate="UserLookup" ValidateEmptyText="true" />
                                            </td>
                                            <td valign="top">
                                                <asp:Button ID="btnAdd" runat="server" OnClick="btnAdd_Click" Text="Add User" ValidationGroup="addUser"
                                                    CausesValidation="true" CssClass="ButtonS1" Style="margin: 2px 0px 8px 2px;" />
                                            </td>
                                        </tr>
                                    </table>
                                </asp:Panel>
                            </ContentTemplate>
                            <Triggers>
                                <asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" />
                            </Triggers>
                        </asp:UpdatePanel>
                    </td>
                </tr>
                <tr style="vertical-align: top">
                    <asp:Panel ID="queryConditionPanel" runat="server" Visible="false">
                        <td>
                            <asp:Label ID="lblQueryCondition" runat="server" Text="Query&nbsp;Condition:" Width="138px" />
                        </td>
                        <td>
                            <accenture:lengthlimitedmultilinetextbox id="txtQueryCondition" runat="server" text='<%# Bind("QueryCondition") %>'
                                style="width: 500px" textmode="MultiLine" maxlength="1000" height="100px" cssclass="txtbox" />
                        </td>
                    </asp:Panel>
                </tr>
            </table>
        </EditItemTemplate>
        <InsertItemTemplate>
            Gid:
            <asp:TextBox ID="GidTextBox" runat="server" Text='<%# Bind("Gid") %>' /><br />
            GroupName:
            <asp:TextBox ID="GroupNameTextBox" MaxLength="50" runat="server" Text='<%# Bind("GroupName") %>' /><br />
            Id:
            <asp:TextBox ID="IdTextBox" runat="server" Text='<%# Bind("Id") %>'></asp:TextBox><br />
            GroupDescr:
            <asp:TextBox ID="GroupDescrTextBox" MaxLength="255" runat="server" Text='<%# Bind("GroupDescr") %>' /><br />
            ExcludeFromUserFilter:
            <asp:CheckBox ID="chbExcludefromDocFilter" runat="server" Checked='<%# Bind("ExcludeFromUserFilter") %>' /><br />
            Members:
            <asp:TextBox ID="MembersTextBox" runat="server" Text='<%# Bind("Members") %>' /><br />
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                Text="Insert" />
            <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel" />
        </InsertItemTemplate>
        <ItemTemplate>
            Gid:
            <asp:Label ID="GidLabel" runat="server" Text='<%# Bind("Gid") %>' /><br />
            GroupName:
            <asp:Label ID="GroupNameLabel" runat="server" Text='<%# Bind("GroupName") %>' /><br />
            Id:
            <asp:Label ID="IdLabel" runat="server" Text='<%# Bind("Id") %>' /><br />
            GroupDescr:
            <asp:Label ID="GroupDescrLabel" runat="server" Text='<%# Bind("GroupDescr") %>' /><br />
            <%--ExcludeFromUserFilter: <asp:Label ID="lblExcludefromDocFilter" runat="server" Text='<%# Bind("ExcludeFromUserFilter") %>' /><br />--%>
            Members:
            <asp:Label ID="MembersLabel" runat="server" Text='<%# Bind("Members") %>' /><br />
            <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                Text="Edit" />
        </ItemTemplate>
    </asp:FormView>
    <asp:Label ID="lblMsg" runat="server" ForeColor="Red" />
    <asp:ObjectDataSource ID="PermGroupObjectDataSource1" runat="server" DataObjectTypeName="Accenture.CSTPrague.eAPI.PermGroup"
        SelectMethod="FetchPermGroupFromDB" TypeName="Accenture.CSTPrague.eAPI.WebDB_Perm"
        UpdateMethod="StorePermGroupToDB" OnUpdating="PermGroupObjectDataSource1_Updating">
        <SelectParameters>
            <asp:SessionParameter Name="o" SessionField="oPermGroup" Type="Object" />
        </SelectParameters>
    </asp:ObjectDataSource>
</div>
</form>

1 个答案:

答案 0 :(得分:0)

在验证控件和提交按钮中设置ValidationGroup =“xxx”。(不要取消按钮“)

尝试

<asp:RequiredFieldValidator ID="rqrgFldVldtr_GroupName" 
             ControlToValidate="GroupNameTextBox" **ValidationGroup="xxx"** Display="Dynamic" ErrorMessage="&lt;"
                            meta:resourcekey="RequiredFieldValidator1Resource2" 
              runat="server">
           </asp:RequiredFieldValidator>

<asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click"  **ValidationGroup="xxx"** Text="Save" 
            Width="67px" CssClass="ButtonS1"/>

            <asp:Button ID="btnCancel" runat="server" OnClick="btnCancel_Click" 
           Text="Cancel" CssClass="ButtonS1" CausesValidation="false"/>