This is a migrated thread and some comments may be shown as answers.

Tab Strip - Validate Multiple Tabs Individually

2 Answers 98 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
Josh Pollard
Top achievements
Rank 1
Josh Pollard asked on 24 Sep 2009, 01:18 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Paul
Telerik team
answered on 24 Sep 2009, 01:38 PM
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.
0
Josh Pollard
Top achievements
Rank 1
answered on 24 Sep 2009, 01:45 PM
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.

Tags
TabStrip
Asked by
Josh Pollard
Top achievements
Rank 1
Answers by
Paul
Telerik team
Josh Pollard
Top achievements
Rank 1
Share this question
or