ASP.net的RequiredFieldValidator没有preventing回传 [英] ASP.net RequiredFieldValidator not preventing postback

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

问题描述

我有什么可以阻止从$ P $一个RequiredFieldValidator pventing回传的问题。

I have a question about what could stop a RequiredFieldValidator from preventing a postback.

我开始在一个旧的工作,但简单的aspx的形式和我的predecessor使用手册,服务器端表单验证(检查是否某种形式的领域有值,如果不显示在标签中的错误消息) 。我以为我会清理一些不需要code和替换的RequiredFieldValidator控制手工检查,但是当他们似乎是验证,他们不是preventing回发。即,我得到我的显示错误消息,但回发仍会发生。

I began working on an older, but simple aspx form and my predecessor used manual, server-side form validation (checking to see if some form fields have a value and if not displaying an error message in a label). I thought I'd clean out some unneeded code and replace the manual checking with RequiredFieldValidator controls, but while they appear to be validating, they aren't preventing a postback. Ie., I get my error messages displayed but the postback still occurs.

的形式是相当简单和不存在的CausesValidation =假的属性集。我的控制是这样的:

The form is quite simple and there are no CausesValidation="false" attributes set. My controls look like:

 <asp:TextBox ID="txtPhone" Runat="server" Columns="20" MaxLength="20" />
 <asp:RequiredFieldValidator ID="rfvPhone" runat="server" Display="Dynamic"
      ErrorMessage="* Required" ControlToValidate="txtPhone" />

我创建了一个全新的表单在同一项目中只有一个单一的文本框,验证和提交按钮,它的作用是一样的。显示错误消息,但回发仍然存在。

I created a brand new webform in the same project with just a single textbox, validator and submit button and it acts the same way. Error message displays but postback still occurs.

有没有会导致此行为的全球性或项目范围的设置?在web.config或Global.asax的东西吗?

Is there a global or project-wide setting that would cause this behaviour? Something in the web.config or global.asax?

推荐答案

哇。好吧,我发现这个问题,基本上通过创建一个全新的项目和它的web.config行由行与我的老项目相比。原来,罪魁祸首是这样的:

Whew. Okay, I found the problem, basically by creating a brand new project and comparing its web.config line-by-line with my old project. Turns out the culprit is this:

 <xhtmlConformance mode="Legacy"/>

如果我删除行,我的验证工作我预期的方式。谷歌搜索发现那一堆有关从.NET 1.1升级的Web应用程序时,.NET 3.5的VisualStudio如何补充说,行到web.config博客帖子。

If I remove the line, my validation works the way I expected it to. Googling that uncovered a bunch of blog posts about how VisualStudio adds that line to the web.config when upgrading web apps from .net 1.1 to .net 3.5.

博客文章主要是在抱怨那场与.NET的AJAX的东西是如何干涉,但我猜它在以类似的方式发出的RequiredFieldValidator JavaScript的食堂。

The blog posts were mainly complaining about how that field interferes with .net's AJAX stuff, but I'm guessing it messes with the JavaScript emitted for the RequiredFieldValidator in a similar fashion.

这篇关于ASP.net的RequiredFieldValidator没有preventing回传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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