调用ASP.net验证程序的回调方法 [英] Calling callback method for ASP.net validators

查看:448
本文介绍了调用ASP.net验证程序的回调方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Web应用程序,其中在其中显示某些字段的水印文本.

I am creating one web application in which I am showing watermark text for some fields.

例如:我有一个文本框名称",其中将填充名称"显示为水印.我为此文本框提供了一个必填字段验证器.因此,我将清除所需的字段验证器之前的文本框,否则将填充名称"视为有效数据,并且将不应用验证.但是,如果验证失败,则不会出现水印.我们可以在asp.net验证器上注册某种回调方法吗?

For example: I have one text box "Name" in which I am showing "Fill Name" as watermark. I have one required field validator for this text box. So, I am clearing the text box before the required field validator chck the text box other wise it will treat "Fill Name" as valid data and it will not apply validations. But when the validations fails, the watermark is not coming. Can we register some kind of callback method on asp.net validators?

我只想在asp.net验证失败时运行一个Java脚本函数.

I just want to run one java script function when asp.net validations fails.

谢谢阿什瓦尼(Ashwani)

Thanks Ashwani

推荐答案

我已经找到了解决方案.

I got the solution for this.

function HookFunction() {
    var Original_ValidatorUpdateDisplay = ValidatorUpdateDisplay;
    ValidatorUpdateDisplay = function (val) {
        Original_ValidatorUpdateDisplay(val);
        if (val) {
            val.style.display = val.isvalid ? "none" : "inline-block";
        }
    };
    var Original_ValidatorSetFocus = ValidatorSetFocus;
    ValidatorSetFocus = function (val, event) {
        if (val) {
            ClearWaterMarkText($('#' + $(val).attr('controltovalidate')));
        }
        Original_ValidatorSetFocus(val, event);
    };
}

这篇关于调用ASP.net验证程序的回调方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆