views:

26

answers:

1

Is there an easy way to determine what controls are failing validation on an ASP.NET web site? I am debugging a page where Page.Validate("group") fails, but I don't know what controls made the page fail. The page is rather big and the code a bit messy, so I am hoping that I could get a list of the IDs of the controls that are failing validation.

I have tried adding a ValidationSummary to the page, but that just gives me a standard "please fill in a value" message for the three controls that a failing because that's the standard text that we use on the web site.

A: 

Here is how I did it on the client side.

function ValidationCatcher()
{
    //force .net validation
    Page_ClientValidate();

    var count = 0;
    for(i=0; i < Page_Validators.length; i++){
        if(!Page_Validators[i].isvalid)
        {
            //do whatever
            count = count+1;
        }
    }
    //set msg for dialog message
    //do whateveryou want here
    alert(count);

}

function ValidatorFocus()
{
    var i;
    for (i = 0; i < Page_Validators.length; i++) {
        if (!Page_Validators[i].isvalid) {
            document.getElementById(
            Page_Validators[i].controltovalidate).focus();
            break;
        }
    }
}
rick schott
I did not know that Page.Validators existed. Just what I needed. Thanks a lot for the help.
Jan Aagaard