我怎样才能prevent页面验证失败后跳转到顶部位置? [英] How can I prevent a page to jump to top position after failed validation?

查看:123
本文介绍了我怎样才能prevent页面验证失败后跳转到顶部位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个文本框和一个提交按钮一个简单的aspx页面。某些字段是必需的,下面的按钮是的ValidationSummary。完整的形式比屏幕高度大所以一个个有向下滚动才能到达提交按钮。如果我不填写所有必填字段,然后点击提交的预期和验证摘要显示按钮下方的一些信息的消息验证失败。验证发生在客户端上,并没有回发发生。

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.

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

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.

有没有办法来prevent此页面跳转?

Is there a way to prevent this page jump?

感谢你在前进!

更新:

我上面描述的行为似乎并没有被依赖于浏览器。我已经在五个不同的浏览器测试,它无处不在一样的。

The behaviour I described above doesn't seem to be browser dependent. I've tested in five different browsers and it's everywhere the same.

推荐答案

我问过的问题上asp.net(<一个href=\"http://forums.asp.net/p/1545969/3779312.aspx\">http://forums.asp.net/p/1545969/3779312.aspx) ,并得到了答复有两个解决方案更好的是这段JavaScript它保持滚动位置:

I've asked the question on asp.net (http://forums.asp.net/p/1545969/3779312.aspx) and got replies with two solutions. The better one is this piece of Javascript which maintains the scroll position:

<script type="text/javascript">
    window.scrollTo = function( x,y ) 
    {
        return true;
    }
</script>

这是只把页面上,也无处可调用。

This is only to put on the page and nowhere to call.

另一个解决方案是类似于在这里RioTera的建议(使用 MaintainScrollPositionOnPostBack ),但增加了 EnableClientScript =假来验证器强制回发。它的工作原理也一样,但价格是人工回发。

The other solution is similar to RioTera's proposal here (using MaintainScrollPositionOnPostBack) but adds EnableClientScript="false" to the Validators to force a postback. It works too, but the price is an artificial postback.

这篇关于我怎样才能prevent页面验证失败后跳转到顶部位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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