3

In tab container let say I have two tabs [Tab1 & Tab2]

Tab1 has 2 text box with required field validator

Tab2 has 3 text box with required field validator

Now even if I am filling all the text boxes in the TAB1, it is not allowing me to postback. [because TAB2 text boxes are still empty]

& When I am filling all the textboxes [Both Tab1 & Tab2], button is firing correctly.

How to avoid this ??

I mean user has to fill details for the TAB1 & can submit the details. At that Time I don't want TAB2 validations to work.

Please help & kindly let me know if anything else is required.

leppie
  • 115,091
  • 17
  • 196
  • 297
Zerotoinfinity
  • 6,290
  • 32
  • 130
  • 206

2 Answers2

2

Add ValidationGroup="Tab1" property to controls and their respective validators which are on the first tab, and ValidationGroup="Tab2" for second tab controls.

Roman Boiko
  • 3,576
  • 1
  • 25
  • 41
1

Or you add validatorgroups programmatically:

protected void Page_Init(object sender, EventArgs e)
{
    foreach (TabPanel tp in Tabs1.Tabs)
        SetValidatorGroup(tp.Controls, string.Format("{0}_ValidatorGroup", tp.ID));
}

private void SetValidatorGroup(ControlCollection cc, string validatorGroup)
{
    foreach (Control c in cc)
    {
        if (c is BaseValidator)
        {
            //Response.Write(string.Format("ValidationGroup '{0}' on Control {1}<br />", validatorGroup, c.ID));
            ((BaseValidator)c).ValidationGroup = validatorGroup;
        }
        else if (c is IButtonControl)
        {
            //Response.Write(string.Format("ValidationGroup '{0}' on Control {1}<br />", validatorGroup, c.ID));
            ((IButtonControl)c).ValidationGroup = validatorGroup;
        }
        else
            SetValidatorGroup(c.Controls, validatorGroup);
    }
}
Schleicher
  • 11
  • 1