views:

15

answers:

3

My page scrolls down a bit, so the problem is when the ASP.NET validation kicks in (its a server side validation that sets a table row to visible if there was a failed validation for a given input box).

The problem is, when there is an error, the page scrolls back to the top.

How can I force the page to the bottom?

I can use <a name="asdf"></name> but the page doesn't refresh normally since its a asp.net image button.

A: 

you could use the JavaScript window.scrollTo(x,y) method

function myScrollFunction(){
    window.scroll(400,400);
}

Add a clients side startupscript to call this function with appropriate values when your serverside validation fails.

Daniel Dyson
any cross browser issues?
Blankman
Shouldn't be. Some people have javascripts turned off in their browsers but I don't know how they use much of the internet if they do.
Daniel Dyson
+2  A: 

If your error is near the button that performs the postback then you can set MaintainScrollPosition in the Page Declaration which will take you back to where you were after the postback.

Robin Day
A: 

you can set it to scroll to the last control on the page:

Page.RegisterStartupScript("MyScrollingStuff", "<script language='javascript'>document.getElementById('" & myControl.ClientID & "').scrollIntoView();</script>")

or cheat:

<script>self.scrollTo(0, 2000000000);</script>
Glennular