Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have an MVC view that after the client click a button a partial view is rendered.

I want to use: window.scrollTo(0, document.body.scrollHeight); after the partial view is fully rendered, so the client will "jump" to the result of the click.

the thing is: it fires before the partial view is rendered and goes to the bottom of the screen as is before the page height is extanded...

how can I force it to wait untill the partial view is fully rendered?

Thank you!

share|improve this question
    
are you loading the partial view via ajax? – MichaC Nov 19 '13 at 14:03
    
    
yes: $('#___').load('/Home/___?departmentId=' + departmentId); – Shlo Nov 19 '13 at 14:05
    
I'm curious if adding window.scrollTo(0, document.body.scrollHeight);directly in the partial view would help. – Andrei V Nov 19 '13 at 14:06
    
@Matt I was looking for a "cleaner" way then using delay or setTimeoUt. Thanx. – Shlo Nov 19 '13 at 14:08
up vote 1 down vote accepted

If you use $().load your can use the callback to do whatever you want when load is done.

$('#___').load('/Home/___?departmentId=' + departmentId, function() {
  alert( "Load was performed." );
});
share|improve this answer
    
that was exactlly what i was looking for. thanks! – Shlo Nov 19 '13 at 16:23

Simply place that

   <script type="text/javascript">
    function ScrollTobottam() {
        window.scrollTo(0, document.body.scrollHeight);
    }
</script>

at bottom of partial view then it will load only after partial view is loaded fully

share|improve this answer
    
Injecting javascript to the page through partial views is just bad design. It's the same crap as UpdatePanel was/is in ASP.NET... – MichaC Nov 19 '13 at 14:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.