是否使用Page_IsValid或Page_ClientValidate()(用于客户端活动) [英] Whether to use Page_IsValid or Page_ClientValidate() (for Client Side Events)

查看:286
本文介绍了是否使用Page_IsValid或Page_ClientValidate()(用于客户端活动)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下一个按钮单击处理程序中code。这两种方法都做工精细。在 Page_ClientValidate()将导致额外的验证检查,并做处理而 Page_IsValid 利用现有的财产。

问题


  1. 在点击按钮的情况下,它总是保证 Page_IsValid 将已通过时间来计算?如果不能保证,我们需要调用 Page_ClientValidate()明确。

  2. 什么是前 Page_IsValid 所发生事件的设置?对于这样的事件,我们不应该依赖于 Page_IsValid

更新

难道放心,验证部分完成后,方可按钮单击事件处理(在JavaScript)将会被调用(即Page_ClientValidate()被调用作为验证的一部分之后)?如果这样吧,我可以依靠Page_IsValid?

SCRIPT

  $('#btnSave')。点击(函数(五){  //阿布罗奇1
  VAR的isValid = Page_ClientValidate('');
  如果(的isValid)
  {
       //做reamining工作
  }  //阿布罗奇2
  如果(Page_IsValid)
  {
      //做reamining工作
  }  });

参考


  1. Hide在ASP.Net的ValidationSummary
  2. 冗余错误信息
  3. Validator为使双击检查
  4. 行为不当
  5. Page_ClientValidate没有定义

  6. Page_ClientValidate正在验证多次。

  7. MSDN - ASP.NET验证的深度


解决方案

  1. 在单击按钮时, Page_ClientValidate()被调用时(且仅当)按钮的的CausesValidation 设置为真正


  2. 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

  1. 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 call Page_ClientValidate() explicitly.
  2. What are the events that happen before Page_IsValid is set? For such events we should not rely on Page_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:

  1. Hide redundant error message in ASP.Net ValidationSummary
  2. Validator causes improper behavior for double click check
  3. Page_ClientValidate is not defined
  4. Page_ClientValidate is validating multiple times.
  5. MSDN - ASP.NET Validation in Depth

解决方案

  1. In case of button click, Page_ClientValidate() is called when (and only when) the button's CausesValidation is set to true.

  2. Page_ClientValidate() is part of process of doing postback, so it is called within button's click.
    I rely on Page_IsValid only in a scope of a function after calling Page_ClientValidate(). Otherwise I always call Page_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屋!

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