Monday, March 26, 2012

Validation

In the validation issue, is there any way to get the list of the controls that fails the validation in a form?

Thankx,
AndreaYou can get to the validators and figure out if they are valid or not:

server side


if Page.Validators.Item(0).IsValid then
...

Client side


if(typeof(Page_Validators) != "undefined")
{for (i = 0; i < Page_Validators.length; i++)
if (!Page_Validators[i].isvalid)
Page_Validators[i].style.visibility = blnTimerFlagSet ? "visible" : "hidden";
}


Hi Bug, your suggstion is valid, but I kindly ask you help for a problem a bit complex.

There is a WebForm, this one contains the IE TabStrip control with 2 tabstrips, and each tabstrip contains for example 1 TextBox. Each TextBox has its own Validator control.

My problem is on the Save event: when the user click the save button I test the IsValid event, and the test checks for users's error, but suppose you are in the first tabstrip, and the error occur in the second one, how can I illustrate to the user that the error is in the second tabstrip?

I would to use the

tabstrip.SelectedIndex = n
to shift to the tabstrip that contains the error, but how can I calculate the correct tabstrip (the n number)?

Thankx,
Andrea
Yeah, would be nice if there was a Tag property of it but...... .In this case i suggest you try using the Parent property of the validator

In case this does not work i could suggest you storing the tabstrips selected index property as part of the validators, say, Id (id="MyValidator_4). You will be able to easily extract it then. Not an ideal solution but... will work

No comments:

Post a Comment