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 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With