ASP.NET 1.X 到 ASP.NET 2.0:回发验证失效

发布于 2024-07-19 10:04:18 字数 1487 浏览 4 评论 0原文

美好的一天,

我们已将 Web 应用程序从 ASP.NET 1.1 迁移到 ASP.NET 2.0。

我们有一个页面,其中包含几个文本框及其各自的验证器。

在 .NET 1.1 上,当文本框包含 INVALID 值时,单击“提交”按钮将不会产生回发(EG 不会发生任何情况)。

然而,当我们迁移到.NET 2.0时,即使存在INVALID值,回发仍然会发生。 (EG 按“提交”按钮将执行回发)。

从 1.1 迁移到 2.0 时验证是否存在问题?

附加信息: “提交”按钮是一个输入按钮:

<input type="button">

使用 代替 按钮将起作用并解决问题。 但是, 能够调用 JavaScript,在页面上生成“等待...正在加载”标签叠加层。 使用 asp:button,“等待...正在加载”覆盖 javascript 将不会被调用。

编辑:真正的问题和解决方案。

无论如何,真正的问题是单击验证 JavaScript 在迁移过程中被破坏。

原始的工作脚本是:

<input language="javascript" onclick="{if (typeof(Page_ClientValidate) != 'function' ||  Page_ClientValidate()) __doPostBack('m_bt_Save','')} " name="m_bt_Save" id="m_bt_Save" type="button" value="Save" width="80px" height="24px" />

但 ASP.NET 2.0 将其更改为:

<input onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(''); __doPostBack('m_bt_Save','')" name="m_bt_Save" type="button" id="m_bt_Save" value="Save" width="80px" height="24px" />

所以我的解决方案是,将 INPUT 按钮更改为 ASP:button,然后添加使用正确的 ASP.NET 1.1 javascript 验证进行页面加载的属性,如下所示:

m_bt_Save.Attributes.Add("OnClick", "if (typeof(Page_ClientValidate) != 'function' ||  Page_ClientValidate()) __doPostBack('m_bt_Save','')");

Good Day,

We have migrated our web application to ASP.NET 2.0 from ASP.NET 1.1.

We have a page that contains a couple of textboxes with their respective Validators.

On .NET 1.1, when a textbox contains an INVALID value, clicking on the "submit" button, will not produce a postback (E.G. Nothing will happen).

However, when we migrated to .NET 2.0, even if there is an INVALID value, the postback will still happen. (E.G. Pressing the "submit" button will perform a postback).

Is there an issue with validation when migrating from 1.1 to 2.0?

Additional Infos:
The "submit" button is an input button:

<input type="button">

Using an <asp:button> in place of the <input> button will work and will fix the problem. However, the <input type="button"> has the capability to call a javascript that will produce a "Wait... Loading" label overlay on the page. Using the asp:button, the "Wait... Loading" overlay javascript will NOT be invoked.

EDIT: Real problem and solution.

Anyway, the real problem is that the on-click validation javascript was broken during migration.

The original and working script is:

<input language="javascript" onclick="{if (typeof(Page_ClientValidate) != 'function' ||  Page_ClientValidate()) __doPostBack('m_bt_Save','')} " name="m_bt_Save" id="m_bt_Save" type="button" value="Save" width="80px" height="24px" />

But ASP.NET 2.0 changed it to:

<input onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(''); __doPostBack('m_bt_Save','')" name="m_bt_Save" type="button" id="m_bt_Save" value="Save" width="80px" height="24px" />

So the my solution was, change the INPUT button to an ASP:button, then add the attribute doing page load with the correct ASP.NET 1.1 javascript validation like so:

m_bt_Save.Attributes.Add("OnClick", "if (typeof(Page_ClientValidate) != 'function' ||  Page_ClientValidate()) __doPostBack('m_bt_Save','')");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

墨小沫ゞ 2024-07-26 10:04:19

你可以做的一件事是,你可以将你需要的 JS 添加到按钮中。

Button1.Attributes.Add("OnClick", "do my js stuff here");

这将使您拥有与输入完全相同的功能,并且使其正常工作。

否则,我的猜测是,您将需要修改输入按钮提交的方式,以在提交之前调用验证页面方法。

One thing you can do, is you can just add your JS that you need to the button.

Button1.Attributes.Add("OnClick", "do my js stuff here");

That will allow you to have the exact same functionality as the input, and it makes it work.

Otherwise, my guess is that you will need to modify the way the input button submits to call the validate page method before it does the from submit.

零度℉ 2024-07-26 10:04:19

我们的升级也发生了这种情况。 我认为我们将问题范围缩小到了 WebUIValidation.js 文件的问题。 我认为重新安装它是我们的最终解决方案。

This happened in our upgrade as well. I think we narrowed it down to a problem with the WebUIValidation.js file. I think re-installing it was the final fix for us.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文