In tab con开发者_StackOverflowtainer 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.
Add ValidationGroup="Tab1"
property to controls and their respective validators which are on the first tab, and ValidationGroup="Tab2"
for second tab controls.
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);
}
}
精彩评论