ASP.Net验证摘要导致跳转到首页 [英] ASP.Net validation summary causes page to jump to top
问题描述
我有一个简单的形式与一些必填字段验证器和一个验证摘要控制。当我提交表单时,的客户的验证会导致形式跳转到页面顶部。如果我删除了验证摘要,页面不动。
I have a simple form with a few required field validators and a validation summary control. When I submit the form, the client validation will cause the form to jump to the top of the page. If i remove the validation summary, the page does not move.
下面有一个简单的例子:
Heres a quick example:
<asp:TextBox ID="test" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="testrequired" runat="server" ControlToValidate="test">*</asp:RequiredFieldValidator>
<asp:ValidationSummary ID="summary" runat="server" />
<asp:Button ID="submit" runat="server" Text="submit" />
我试过设置 SetFocusOnError =真正的
在必填字段验证器和 MaintainScrollPositionOnPostback =真正的
为笑声 - 尽管这不是一个回发 - 没有任何运气。是否有此问题的已知的解决方案?
I've tried setting SetFocusOnError="true"
in the required field validator and MaintainScrollPositionOnPostback="true"
for giggles - even though this isn't a postback - without any luck. Is there a known solution for this problem?
编辑:
我发现通过WebResource.axd的生成JS的问题。似乎归结为在 ValidationSummaryOnSubmit()
函数一行。
I've found the problem in the js generated by WebResource.axd. Seems to come down to a single line in the ValidationSummaryOnSubmit()
function.
line 534: window.scrollTo(0,0);
如何删除或任何想法绕过此?
Any ideas on how to remove or bypass this?
EDIT2:
快速变通暂时
- 设置
EnableClientScript =假
所有验证控件(禁用客户端验证) - 设置
MaintainScrollPositionOnPostback =在Page指令真实
- set
EnableClientScript="false"
for all validation controls (disabling client validation) - set
MaintainScrollPositionOnPostback="true"
in Page directive
仍然希望一个客户端解决方案...
Still hoping for a client side solution...
EDIT3:
这似乎是一个更好的解决办法是只覆盖 window.scrollTo()
功能,以便当验证脚本调用它什么都不做:
It seems a better work around is to just override the window.scrollTo()
function so that it does nothing when called by the validation script:
<script type="text/javascript">
window.scrollTo = function() { }
</script>
添加上述页面上的任何地方留下的机智客户端验证,但禁用 window.scrollTo()
方法在整个页面
推荐答案
有两种可能的变通:
禁用客户端验证并跳转到更正后的位置回:
Disable client validation and jump to correct position on post back:
* set EnableClientScript="false" for all validation controls (disabling client validation)
* set MaintainScrollPositionOnPostback="true" in Page directive
禁用scrollTo功能在JavaScript:
Disable the scrollTo function in javascript:
<script type="text/javascript">
window.scrollTo = function() { }
</script>
这篇关于ASP.Net验证摘要导致跳转到首页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!