是否使用Page_IsValid或Page_ClientValidate()(用于客户端活动) [英] Whether to use Page_IsValid or Page_ClientValidate() (for Client Side Events)
问题描述
我有以下一个按钮单击处理程序中code。这两种方法都做工精细。在 Page_ClientValidate()
将导致额外的验证检查,并做处理而 Page_IsValid
利用现有的财产。
问题
- 在点击按钮的情况下,它总是保证
Page_IsValid
将已通过时间来计算?如果不能保证,我们需要调用Page_ClientValidate()
明确。 - 什么是前
Page_IsValid
所发生事件的设置?对于这样的事件,我们不应该依赖于Page_IsValid
更新
难道放心,验证部分完成后,方可按钮单击事件处理(在JavaScript)将会被调用(即Page_ClientValidate()被调用作为验证的一部分之后)?如果这样吧,我可以依靠Page_IsValid?
SCRIPT
$('#btnSave')。点击(函数(五){ //阿布罗奇1
VAR的isValid = Page_ClientValidate('');
如果(的isValid)
{
//做reamining工作
} //阿布罗奇2
如果(Page_IsValid)
{
//做reamining工作
} });
参考
- Hide在ASP.Net的ValidationSummary 冗余错误信息
- Validator为使双击检查 行为不当
- Page_ClientValidate没有定义
- Page_ClientValidate正在验证多次。
- MSDN - ASP.NET验证的深度
-
在单击按钮时,
Page_ClientValidate()
被调用时(且仅当)按钮的的CausesValidation
设置为真正
。 -
Page_ClientValidate()
是做回发的过程中的一部分,所以它是按钮的点击中调用。结果
我靠Page_IsValid
仅在后一个函数的的范围调用Page_ClientValidate()
。否则,我的总是拨打Page_ClientValidate()
。
注释:调用 Page_ClientValidate()
反复可能会导致页面太突兀(多个警报等)。这就是为什么它的好,有一个自定义验证函数,它的所有验证的照顾。
I have following code inside a button click handler. Both approaches work fine. The Page_ClientValidate()
causes an extra validation check and do processing whereas Page_IsValid
makes use of existing property.
QUESTIONS
- In case of button click, is it always guaranteed that
Page_IsValid
would have been calculated by that time? If is not guaranteed, we need to callPage_ClientValidate()
explicitly. - What are the events that happen before
Page_IsValid
is set? For such events we should not rely onPage_IsValid
UPDATE
Is it assured that the button click event handler (in JavaScript) will be called only after the validation part is completed (i.e., after Page_ClientValidate() was invoked as part of validation) ? If this is assured, can I rely on Page_IsValid?
SCRIPT
$('#btnSave').click(function (e) {
//Aproach 1
var isValid = Page_ClientValidate('');
if (isValid)
{
//Do reamining work
}
//Aproach 2
if (Page_IsValid)
{
//Do reamining work
}
});
REFERENCES:
- Hide redundant error message in ASP.Net ValidationSummary
- Validator causes improper behavior for double click check
- Page_ClientValidate is not defined
- Page_ClientValidate is validating multiple times.
- MSDN - ASP.NET Validation in Depth
In case of button click,
Page_ClientValidate()
is called when (and only when) the button'sCausesValidation
is set totrue
.Page_ClientValidate()
is part of process of doing postback, so it is called within button's click.
I rely onPage_IsValid
only in a scope of a function after callingPage_ClientValidate()
. Otherwise I always callPage_ClientValidate()
.
Comment: calling Page_ClientValidate()
repeatedly may cause the page to be too obtrusive (multiple alerts etc.). That's why it's good to have a custom validate function that takes care of all validation.
这篇关于是否使用Page_IsValid或Page_ClientValidate()(用于客户端活动)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!