ASP.NET:退格键行为

发布于 2024-11-17 22:16:55 字数 431 浏览 3 评论 0原文

我正在用 ASP.NET 和 VB.NET 编写一个内部 Intranet 应用程序。我的“客户”是初级到中级用户。我们所有的浏览器都是 IE8 及以上标准浏览器。

该应用程序运行良好,但有一件事除外。退格键。当用户在文本框中键入无效数字时,RegularExpressionValidator 和 ValidatorCalloutExtender 会触发并通知用户。完美的。除此之外,当用户关闭弹出警告并注意到光标仍在文本框中闪烁时,他/她觉得是时候按退格键并删除该讨厌的字段值了。

不幸的是,浏览器将此操作解释为“返回”页面历史记录的愿望。我的老板在尖叫。他的老板们在尖叫。我头疼。

那么,我怎样才能关闭这种行为呢?我仍然需要退格键来消除文本框中的字符,但仅此而已。公司政策在这里:退格键是从屏幕上删除字符。不多不少。

有什么想法吗?

谢谢,

杰森

I'm writing an in-house intranet application in ASP.NET and VB.NET. My 'customers' are beginner to medium-level users. All of our browsers are IE8 and above, standard.

The application works great, except for one thing. The backspace key. When a user types an invalid number into a textbox, a RegularExpressionValidator and ValidatorCalloutExtender fire off and notify the user. Perfect. Except that, when the user closes the popup warning and notices the cursor is still flashing in the textbox, he/she feels it's time to hit the backspace key and delete that pesky field value.

Unfortunately, the browser interprets this action as a desire to go 'back' into the page history. My boss is screaming. His bosses are screaming. I have a headache.

So, how can I turn off this behavior? I still need the backspace to eliminate characters in the textbox, but nothing else. Company policy here: Backspace is to delete characters from the screen. Nothing more, nothing less.

Any ideas?

Thanks,

Jason

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

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

发布评论

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

评论(5

烟花肆意 2024-11-24 22:16:55

您可以尝试禁用缓存,但这可能会影响性能。我认为有一个 javascript 函数可以修复它:

window.history.forward();

将其与自定义函数配对,如下所示


<脚本类型=javascript>

<代码>
函数disableBack()
{
window.history.forward();
}
setTimeout("disableBack()", 0);

然后在你的 中调用它,

我认为这应该可行,我用过它然而很久以前。让我知道它是否有效!

You could try to disable caching, but that might have performance consequences. I think there is a javascript function that will fix it however:

window.history.forward();

Pair this with in a custom function like so


<script type=javascript>


function disableBack()
{
window.history.forward();
}
setTimeout("disableBack()", 0);

</script>

Then call it in your <body onLoad="disableBack()">

I think this should work, I used it a long time ago however. Let me know if it works!

习惯成性 2024-11-24 22:16:55

也许在这种情况下不使用弹出窗口是一个好方法。

问题是,没有可接受的控件具有焦点,并且在不强制焦点成为所述控件的情况下,浏览器将捕获它。

Perhaps not using a popup in this situation would be a good approach.

The problem is that no acceptable control has focus and without forcing the focus to be said control, the browser will catch it instead.

挖鼻大婶 2024-11-24 22:16:55

当用户关闭弹出窗口时,您可以使用 onClick 事件将表单的焦点设置回 TextBox 吗?我认为这将允许用户恢复编辑文本框值。

When a user closes the popup, can you use that onClick event to set the form's focus back to the TextBox? I would think this would allow the user to resume editing the TextBox value.

恏ㄋ傷疤忘ㄋ疼 2024-11-24 22:16:55

我看到两种可能的解决方案:

  1. 在页面中的 javascript 中捕获按键并防止其冒泡。
  2. 删除弹出警告,并使用“display=dynamic”进行汇总验证。

I see 2 possible solutions :

  1. Trap the keypress in javascript in your page and prevent it from bubbling up.
  2. Remove the popup warning, and use the "display=dynamic" with a summurize validation.
独夜无伴 2024-11-24 22:16:55

如果光标在文本框中闪烁,则退格键也应由输入框处理,并且不应传播到文档对象或窗口对象。如果是这样,您需要调试或使用这个 在文档级别停止传播的技术

If the cursor is flashing in a text box, then the backspace should be handled by the input box as well and not supposed to get propagated to a document object or window object. If it does, you need to debug or use this technique to stop propagation on document level

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