Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 453
roman m Avatar asked Jun 29 '10 22:06

roman m


2 Answers

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

like image 168
Diskdrive Avatar answered Nov 13 '22 05:11

Diskdrive


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.

like image 1
pdr Avatar answered Nov 13 '22 05:11

pdr