,
Share with your friends 

If Validation fails page scrolling to top

0 ratings Views 260 
Author: krish (krishna kumar)  View Profile |  View other solutions by this author

Question / Problem


When I use Validation summary. If some validation fails. immedietly page scrolls to top

Solution


This is the due to default behavior of the validation summary cotrol. If you remove this page won't scroll to top

Solution 1
 Just override the window.onscroll method
just copy and paste the code
<script>
    window.scrollTo = function( x,y ) {
     return true;
    }
</script>

Solution 2
If in your code if you explicitly use scroll to top or some position also fail if you use the solution 1
becuase now you could not call the window.scrollTo method inside your method.
that will give stack overflow error

you could not call the original method too

To solve this copy the reference to soem variable and use that instead of
window.scrollTo method

Code:
var scrollToTop = 'N';

    refScroll = window.scrollTo;
    window.scrollTo = function(x, y) {
        //alert(scrollToTop)

        if (scrollToTop == 'Y') {
            scrollToTop = 'N';
            refScroll(0, 0);
        }
        else
            return true;
    }
Note :  scrollToTop is the variable i used to decide move to top or not

Applies to

ASP.Net 3.5 ,Asp.Net 2.0

Rank It

Login to rank it

Report


Advertisement