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.
精彩评论