Tab Strip - Validate Multiple Tabs Individually

3 posts, 1 answers
  1. Josh Pollard
    Josh Pollard avatar
    5 posts
    Member since:
    Aug 2009

    Posted 24 Sep 2009 Link to this post

    I want to be able to validate all of the controls in all of the tabs in one button click event. I have all of the controls broken out into separate validation groups by their tab. The tricky part is that i want to know what tab has the invalid controls.

    I tried creating an array of my validation groups in the same order as the tabs and then looping through it like so:

    for (int i = 0; i < ValidationGroups.Count - 1; i++)
                {
                    Page.Validate(ValidationGroups[i]);

                    if (!Page.IsValid)
                        RadTabStrip1.Tabs[i].ImageUrl = iconPath;

                }

    The problem is that Page.IsValid will always return false as soon as ANY validation group is false. So if I have invalid controls on the first tab, the Page.IsValid will always return false for every tab after that.

    Does anyone have a better solution? Thanks!
  2. Answer
    Paul
    Admin
    Paul avatar
    4281 posts

    Posted 24 Sep 2009 Link to this post

    Hi Josh,

    Please refer to this KB article for details on the matter.

    Kind regards,
    Paul
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Josh Pollard
    Josh Pollard avatar
    5 posts
    Member since:
    Aug 2009

    Posted 24 Sep 2009 Link to this post

    Thank you. I also found another way to do it.

    I added this function:

            protected bool IsGroupValid(string ValidationGroup) 
            { 
                foreach (BaseValidator validator in Page.Validators) 
                { 
                    if (validator.ValidationGroup == ValidationGroup) 
                    { 
                        bool fValid = validator.IsValid; 
                        if (fValid) 
                        { 
                            validator.Validate(); 
                            fValid = validator.IsValid;                         
                        } 
                        if (!fValid) 
                            return false
                    } 
     
                } 
                return true
            } 

    And then changed my earlier code to this:

                for (int i = 0; i < ValidationGroups.Count - 1; i++) 
                { 
                    if (IsGroupValid(ValidationGroups[i]) == false
                        RadTabStrip1.Tabs[i].ImageUrl = iconPath; 
                } 

    This puts the image stored in the iconPath variable on all of the tabs with invalid controls and fires the validation for each of those controls.

Back to Top