views:

357

answers:

2

I've got a ASP.NET 3.5 sp1 site, and on one page I have two UpdatePanels. The first has a CustomValidator, and the second does not. I want the validation to run ONLY when the button is pressed. Currenlty, when the Gridview in the second updatepanel is edited, it also causes the validation. I've read a lot about how the validation controls in 2.0 used to be messed up, but I'm pretty sure that's not germaine to my problem here (or is it?)

Here's the relevant section of the page...

<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  A: 

You might want to partition the validations using ValidationGroup.

In that way, you can choose to have the button validating only certain controls within the same group.

o.k.w
Worked like a charm. Thanks!
Jon Dewees
+1  A: 

Only part of the solution, but here is a link how to manually call client-side validation in javascript.

the simpler is: Page_ClientValidate('Group1');

Petar Kabashki