1

I have multiView and Validation group in my code. According to my code when user press button all the data in views needs to be saved.

    <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">    
     <asp:View ID="viewGegevens" runat="server">
          <asp:TextBox ID="txtCompanyname" MaxLength="100" runat="server" CssClass=""></asp:TextBox>
          <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ToolTip="Bedrijfsnaam vereist!"
                                Display="Dynamic" ErrorMessage="*" ValidationGroup="Save" ControlToValidate="txtCompanyname"
                                CssClass="required-asterics"></asp:RequiredFieldValidator>

         <div>
            <asp:LinkButton ID="btnSave1" Text="Opslaan" runat="server" CssClass="btn-ctrl right" OnClick="txtSave1_Click" ValidationGroup="Save">Save
            </asp:LinkButton>
            <asp:LinkButton ID="btnCancel1" Text="Annuleren" runat="server" CssClass="btn-ctrl right" OnClick="txtCancel1_Click">  Cancel 
            </asp:LinkButton>    
         </div>
      </asp:View>

      <asp:View ID="viewGegevens2" runat="server">
           <asp:TextBox ID="txtBillingPostalCode" runat="server" CssClass="" MaxLength="100"></asp:TextBox>
           <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ToolTip="Postcode vereist!"
                                ErrorMessage="*" ValidationGroup="Save" ControlToValidate="txtBillingPostalCode"
                                Display="Dynamic" CssClass="required-asterics"></asp:RequiredFieldValidator>

         <div>
            <asp:LinkButton ID="btnSave2" Text="Opslaan" runat="server" CssClass="btn-ctrl right" OnClick="txtSave2_Click" ValidationGroup="Save">Save
            </asp:LinkButton>
            <asp:LinkButton ID="txtCancel2" Text="Annuleren" runat="server" CssClass="btn-ctrl right" OnClick="txtCancel2_Click">  Cancel 
            </asp:LinkButton>    
         </div>
      </asp:View>
    </asp:MultiView>

My problem is i need to fire required field validation in both tabs either user press btnSave1 or btnSave2. But now if i press btnSave1 it only fires validations in 1st tab only. How can i solve this?

2
  • ASP.NET Multiview is designed to display one view at a time. If you inspect the html rendered at the client, you should not see the html of the 2nd view, do you? Commented Apr 22, 2015 at 11:10
  • @zed u r correct. then is that possible to add validation group to tab change event? Commented Apr 22, 2015 at 11:53

3 Answers 3

2

Found a workaround for this that works in my case. I made the different views validate when the tabs are clicked in the code behind preventing the user from leaving the view without validating.

protected void Tab3_Click(object sender, EventArgs e)
{
    Page.Validate("YourValidationGroup");
    if (Page.IsValid)
    {
        Tab1.CssClass = "Initial";
        Tab2.CssClass = "Initial";
        Tab3.CssClass = "Clicked";
        MainView.ActiveViewIndex = 2;
    }
}

I know this in an old thread but figured I'd throw it out there for future people experiencing a similar issue.

Sign up to request clarification or add additional context in comments.

Comments

1

The answer is no, you can't do it like this out of the box.

ASP.NET Multiview is designed to display and validate one view at a time. So only the active view's html is delivered to the client's browser.

There is a workaround but may give you problems if you are using MultiView's ActiveViewChanged event.

Another option would be to refactor your page and use two divs, one for each step, making one or the other visible when changing from first to second step, and validate entire page once in the last step. This will require you to do more work with javascript.

Comments

0

Try this:

SelectView(0);
        Validate();
        if (IsValid)
        {
            SelectView(1);
            Validate();
            if (IsValid)
            {
                SelectView(2);
                Validate();
                if (IsValid)
                {
                    SelectView(3);
                    Validate();
                    if (IsValid)
                    {
                        UpdateHeader();
                        Response.Redirect("FinConfLanding.aspx");
                    }
                }
            }
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.