开发者

ASP.NET: Backspace Key Behavior

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. 开发者_StackOverflow中文版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


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!


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.


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜