Mothware
Mothware

Reputation: 312

list of all validation errors on page post back including hidden fields in multiview

I am working on an .Net Webforms project and on one page there is a multiview that contains many fields that need validation on each view. All have required field validators, but I need to only validate when the user wants to update the saved data, not when they are just looking at it. Because of this the client side doesn't know of the existence of fields from view1 in the multi view when view 5 is the only one visible. Page.isvalid returns false but I need to display all there errors in a validation summary.

Upvotes: 0

Views: 274

Answers (1)

Ronaldinho Learn Coding
Ronaldinho Learn Coding

Reputation: 13824

I am not sure what you really want, I think you mean that you want to display all errors from all the "view" in the ValidationSumary?

Some note: using ValidationGroup for all controls, buttons and validationsumary, put validationsumary outside the views...

The best is to show your code here, but here is a sample of working code that may help you, get this from here

<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
            <asp:View ID="View1" runat="server">
                view 1:&nbsp;&nbsp;<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                &nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                    ControlToValidate="TextBox1" ErrorMessage="RequiredFieldValidator1"></asp:RequiredFieldValidator>
            </asp:View>
             <asp:View ID="View2" runat="server">
                 view 2 :<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                 <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                     ControlToValidate="TextBox2" ErrorMessage="RequiredFieldValidator2">*</asp:RequiredFieldValidator>
            </asp:View>
        </asp:MultiView>

    <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
    <asp:Button ID="Button1" runat="server" Text="submit" />
    &nbsp;&nbsp;
    <asp:Button ID="Button2" runat="server" Text="view2" onclick="Button2_Click" />
    &nbsp;&nbsp;
    <asp:Button ID="Button3" runat="server" Text="view1" onclick="Button3_Click" />

Upvotes: 0

Related Questions