我同时想要RequiredFieldValidator和onClientClick [英] I want both RequiredFieldValidator and onClientClick at the same time

查看:104
本文介绍了我同时想要RequiredFieldValidator和onClientClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个RequiredFieldValidator应用于TextBox。

同时,我按如下方式设置提交按钮的OnClientClick属性:

UpdateButton.OnClientClick =return confirm ('保存更改?');



当我设置onclientclick然后我的验证器不工作

解决方案

< blockquote>我做了同样的事情。它工作正常。你一定做错了。



实际上,当你设置 OnClientClick 属性时,然后这个代码将首先执行,然后如果回发发生验证将被解雇。



在您的情况下,单击UpdateButton,它将显示确认框,如果用户单击OK,则会触发验证,因为页面将尝试回发,如果单击取消,则不会发生任何事情,也不会触发验证。


UpdateButton.OnClientClick =return validateFun();

//在更新按钮的客户端点击事件中调用以下函数

函数validateFun(){

var rf =


get('<%= RequiredFieldValidator1.ClientID%>')

; 
if (rf!= null ){
ValidatorEnable(rf,);
ValidatorValidate(rf);
if (rf.isvalid == true ){
var answer = window.confirm(' 保存更改?');
return answer;
}
else
return ;
}
else
return ;
}


I have a RequiredFieldValidator applied to a TextBox.
At the same time, I set the submit button's OnClientClick property as follows:
UpdateButton.OnClientClick = "return confirm('Save the changes?');"

when i set onclientclick then my validator not work

解决方案

I did the same. And it was working fine.You must be doing something wrong.

Actually, when you set the OnClientClick property, then this code will be executed first, then if postback occurs the validation will be fired.

In your case, On clicking of UpdateButton, it will show the confirmation box, if user clicks OK then validation will be fired because page will try for postback and if clicked Cancel, then nothing will happen and validation will also not be fired.


UpdateButton.OnClientClick = "return validateFun();"
// Call following function in client click event of Update Button
function validateFun() {
var rf=


get('<%= RequiredFieldValidator1.ClientID %>')

;
                if (rf != null){
            ValidatorEnable(rf, true);
                    ValidatorValidate(rf);
                    if(rf.isvalid==true){
            var answer=window.confirm('Save the changes?');
            return answer;
                      }
                     else
                     return false;
            }
         else
         return false;
}


这篇关于我同时想要RequiredFieldValidator和onClientClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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