开发者

How to maintain scroll position after client-side validation fails?

开发者 https://www.devze.com 2023-01-05 00:05 出处:网络
I\'ve got an ASP.NET webform with asp:TextBox and asp:RequiredFieldValidator at the bottom of the page. If client side validation fails on form submit - the page scrolls all the way up.

I've got an ASP.NET webform with asp:TextBox and asp:RequiredFieldValidator at the bottom of the page. If client side validation fails on form submit - the page scrolls all the way up.

I'd like to maintain the scroll position on failed client-side validation.

I've found开发者_JAVA百科 this solution, but it seems overly complex.

Any ideas?


I was a bit stuck with this problem. This seemed to fix the problem for me.

I fixed it by adding this to the OnClientClick event of the input button.

onClientClick="window.scrollTo = function(x,y) { return true; };"

Have a look at here for more analysis. http://blog.waiholiu.info/2011/04/how-to-maintain-scroll-position-of-page.html


The best approach I've found, after looking at this pretty deeply, is to put your error messages at the top of the page in a Summary.

0

精彩评论

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