带验证控件的ASP.NET 3.5 UpdatePanel。验证意外地运行

时间:2010-02-04 03:09:38

标签: asp.net validation .net-3.5 updatepanel

我有一个ASP.NET 3.5 sp1站点,在一个页面上我有两个UpdatePanel。第一个有CustomValidator,第二个没有。我希望验证仅在按下按钮时运行。 Currenlty,当编辑第二个updatepanel中的Gridview时,它也会导致验证。我已经阅读了很多关于2.0中的验证控件如何被搞砸的内容,但我很确定这不是我的问题的原因(或者是它?)

这是页面的相关部分......

<asp:UpdatePanel ID="userInput" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
    <Triggers>
        <asp:PostBackTrigger ControlID="btnSubmit" />
    </Triggers>
    <ContentTemplate>
        <asp:TextBox ID="txtMCCredits" runat="server" Width="28px"></asp:TextBox>
        <asp:CustomValidator ID="UserValidator" runat="server" ErrorMessage="*" OnServerValidate="UserValidator_ServerValidate" />
    </ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
<asp:UpdatePanel ID="upData" runat="server" UpdateMode="Conditional">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="gvMainproCredits" />
    </Triggers>
    <ContentTemplate>
        <asp:GridView ID="gvMainproCredits" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333"
            GridLines="None" DataKeyNames="RecordID">
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <Columns>
                <!--SNIP-->
                <asp:BoundField DataField="RecordID" HeaderText="RecordID" InsertVisible="False"
                    ReadOnly="True" SortExpression="RecordID" Visible="false" />
                <asp:BoundField DataField="DateAdded" HeaderText="DateAdded" SortExpression="DateAdded" />
                <asp:CommandField ShowHeader="true" HeaderText="Edit" ShowEditButton="true" />
            </Columns>
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>

2 个答案:

答案 0 :(得分:4)

您可能希望使用ValidationGroup对验证进行分区。

通过这种方式,您可以选择让按钮仅验证同一组中的某些控件。

答案 1 :(得分:1)

只有解决方案的一部分,但here是如何在javascript中手动调用客户端验证的链接。

更简单的是:   Page_ClientValidate( '组别1');

相关问题