Scroll to first ASP.Net Validation Error on Page

function ScrollToFirstError() {
    Page_ClientValidate();
    if (Page_IsValid == false) {
        var topMostValidator;
        var lastOffsetTop;
        for (var i = 0; i < Page_Validators.length; i++) {
            var vld = Page_Validators[i];
            if (vld.isvalid == false) {
                if (PageOffset(vld) < lastOffsetTop || lastOffsetTop == undefined) {
                    topMostValidator = vld;
                    lastOffsetTop = vld.offsetTop;
                }
            }
        }
        topMostValidator.scrollIntoView();
    }
    return Page_IsValid;
}
function PageOffset(theElement) {
    var selectedPosY = 0;
    while (theElement != null) {
        selectedPosY += theElement.offsetTop;
        theElement = theElement.offsetParent;
    }
    return selectedPosY;
}

Thanks to: http://msdn.microsoft.com/en-us/library/Aa479045

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: