Pill container - button event does not fire

In the tabs container, let's say that I have two tabs [Tab1 and Tab2]

Tab1 has 2 text fields with a required field validator

Tab2 has 3 text fields with a required authentication field

Now, even if I fill in all the text fields in TAB1, this does not allow me to send back. [since the text fields of TAB2 are still empty]

& When I fill in all the text fields [Both Tab1 and Tab2], the button starts correctly.

How to avoid this?

I mean, the user must fill in the details for TAB1 and can send the details. At this time, I do not want TAB2 validations to work.

Please help and kindly let me know if something else is needed.

+3
source share
2 answers

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

+2
source

Or you add validatorgroups program files:

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);
    }
}
+1
source

Source: https://habr.com/ru/post/1737883/


All Articles