开发者

ASP.NET MVC2 - hook into client side validation

I want to trigger some custom code when the client side errors are updated using ASP.NET MVC2 client side validation. I've tracked down this function which I want to hook into:

Sys.Mvc.FormContext.prototype = {

    // ...

    _displayError: function Sys_Mvc_FormContext$_displayError() {
        if (this._validationSummaryElement) {
            if (this._validationSummaryULElement) {
                Sys.Mvc._validationUtil.removeAllChildren(this._validationSummaryULElement);
                for (var i = 0; i < this._errors.length; i++) {
                    var liElement = document.createElement('li');
                    Sys.Mvc._validationUtil.setInnerText(liElement, this._errors[i]);
                    this._validationSummaryULElement.appendChild(liElement);
                }
            }
            Sys.UI.DomElement.removeCssClass(this._validationSummaryElement, Sys.Mvc.FormContext._validationSummaryValidCss);
            Sys.UI.DomElement.addCssClass(this._validationSummaryElement, Sys.Mvc.FormContext._validationSummaryErrorCss);
        }
    },

    // ...

}    

How can I override this function such that my code can


Found it.

<script type="text/javascript">
    $(function () {
        var old_displayError = Sys.Mvc.FormContext.prototype._displayError;
        Sys.Mvc.FormContext.prototype._displayError = function () {
            old_displayError.apply(this);
            // do other stuff here
        }
    });
</script>

I'm not used to overriding prototype functions, so I was stumped for a bit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜