如何防止在asp.net上单击按钮时滚动鼠标指针 [英] How to prevent scrolling of mouse pointer on button click in asp.net

查看:74
本文介绍了如何防止在asp.net上单击按钮时滚动鼠标指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,





我有一个简单的aspx页面,里面有几个TextBox和一个提交按钮。某些字段是必需的,按钮下方是ValidationSummary。完整的表单大于屏幕高度,因此必须向下滚动才能到达提交按钮。如果我没有填写所有必填字段并单击提交验证按预期失败,验证摘要会在按钮下方显示一些信息消息。验证发生在客户端上并且没有发生回发。



所以这一切都按照希望进行。但令人不安的是,当我点击提交按钮时,页面会移动(跳转)到顶部位置。要查看验证摘要,必须再次向下移动页面。



我试图将ShowSummary属性设置为false(这没有多大意义) :验证仍然有效(没有回发),但在这种情况下,页面不会移动到顶部位置。所以这个问题似乎取决于渲染验证文本。



有没有办法防止这个页面跳转?



提前谢谢!

解决方案

请参阅我对我试图解释实际情况的问题的评论。最有可能的是,没有什么能真正跳跃。



有不同的方法来解决这个问题。原则上,您可以通过检查发布数据并确定提交后是否呈现页面,将页面滚动到提交时的位置。但我认为这不是解决问题的最佳方式。用户可以在提交时具有不同的滚动位置。此位置甚至可以不显示提交按钮,因为用户可以使用键盘访问键来调用按钮单击。因此,即使您成功滚动到显示按钮的位置,它也可能不是最适合用户体验的。



这是一个非常常见的问题,我认为我看到的最佳解决方案基于不同的页面设计。
  • 这样的一些页面忽略了这个问题。如果用户提交了该页面,此人需要查看提交结果(并且您应该提供足够的反馈),而不是再次提供相同的按钮。我实际上听到了一些用户的抱怨,他们看到使用提交按钮的同一页面感到困惑,因为他们无法清楚地看到他们是否真的成功提交了数据。



    所以,即使你可能觉得它很奇怪,基于忽略问题的解决方案(但实际上是在回发后显示的不同视觉反馈补偿)可能是最好的方法之一。
  • 一些页面显示顶部的提交按钮或两个相同的提交按钮:顶部和底部。也许有点难看,但是很有效。
  • 最后,其他一些页面会在页面上的不可滚动的列或行中显示提交按钮,以及其他一些始终显示的内容。非常简单和漂亮。




它可能是别的东西。在所有合理的变体中,真正的解决方案是更好的UI设计,而不是修复滚动位置。



-SA

hello guys,


I have a simple aspx page with a few TextBoxes and a submit button. Some fields are required and below the button is a ValidationSummary. The complete form is larger than screen height so one has to scroll down to reach the submit button. If I don't fill all required fields and click on submit validation fails as expected and the validation summary displays some info messages below the button. Validation happens on the client and no postback occurs.

So this all works as wished. But disturbing is that the page moves ("jumps") to top position when I click on the submit button. To see the validation summary one has to move down the page again.

I've tried to set the ShowSummary property to false (which doesn't make much sense): The validation still works (no postback) but in this case the page does not move to top position. So the problem seems to depend on rendering the validation texts.

Is there a way to prevent this page jump?

Thank you in advance!

解决方案

Please see my comment to the question where I tried to explain what actually happens. Most likely, nothing really "jumps".

There are different ways to solve this problem. In principle, you can scroll the page to the position at the moment of submit by checking the post data and figuring out if the page is being rendered after submit. But I think this is not the best way to deal with the issue. The user can have different scroll positions at the moment of submit. This position can even be without showing the Submit button, because the user could use the keyboard access key to invoke the button click. So, even if you successfully scroll to the position showing the button, it might not be the best for user experience.

This is a very common problem, and I think the best solutions I saw are based on different page design.
  • Some pages like that ignore the problem. If a user has submitted the page, this person needs to see the result of submission (and you should provide adequate feedback), not the same button again. I actually heard a number of complains from the users who get confused by seeing the same page with Submit button, because they cannot clearly see if they actually successfully submitted data or not.

    So, even though you may find it weird, the solution based on "ignoring the problem" (but actually compensated by distinct visual feedback in shown after postback) is probably one of the best approaches.
  • Some pages show Submit button on top or two identical submit buttons: top and bottom. Perhaps a bit ugly, but works.
  • And, finally, some other pages show the Submit button in a non-scrollable column or row on the page, along with some other "always shown" content. Pretty simple and nice.


It could be something else. In all the reasonable variants, the real solution is better UI design, not "fix" of the scroll position.

—SA


这篇关于如何防止在asp.net上单击按钮时滚动鼠标指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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