必填字段验证器未触发 [英] Required Field Validator Not Firing

查看:90
本文介绍了必填字段验证器未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对带有文本框和RequiredFieldValidator的标准ASP.NET页面有问题.复制步骤非常简单:

I'm having an issue with a standard ASP.NET page that has a TextBox and a RequiredFieldValidator. The steps to reproduce are quite simple:

  1. 在页面上放置文本框
  2. 在页面上放置RequiredFieldValidator
  3. 将RequiredFieldValidator指向文本框
  4. 运行应用
  5. 远离TextBox,RequiredFieldValidator不会显示
  6. 输入文本,然后删除文本和然后"选项卡,RequiredFieldValidator会显示

RequiredFieldValidator在回发后的两种情况下都可以正常工作,但是,直到在文本框内输入某些内容(然后将其删除)后,客户端代码才可能触发.

The RequiredFieldValidator works fine in both cases after a postback, however it seems the client-side code isn't firing until something is entered into the textbox (and then deleted).

有人可以解决这个问题,而不必自己动手使用JavaScript吗?

Does anyone have a solution to this without hacking away at JavaScript myself?

推荐答案

这种行为是否有可能是设计使用户无法确认验证控件的外观,直到用户输入?

Is it possible this behavior is by design to suppress the appearance of validation controls until user input?

通常来说,每当单击将CausesValidation设置为true的控件(如提交按钮)时,都将调用Validate().

Generally speaking, Validate() gets called whenever a control is clicked that has CausesValidation set to true, like a submit button.

无论如何,如果有一个穷人解决,您可以可以从Load事件处理程序中调用页面Validate()函数.这样会使事情更加清晰,以使喜欢的用户可以选择需要输入的内容.例如

In any case, a poor mans work around, you could call the page Validate() function from the Load event handler. This will make things clearer to tab happy users that they need to enter something in. E.g.

protected void Page_Load(object sender, EventArgs e)
{
    Validate();
}

这篇关于必填字段验证器未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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