0

My question is that how to set a starting point for a webpage when it is loaded. I have some information in a content placeholder, when the form containing the content placeholder is loaded instead of displaying the information in the content placeholder it goes back to the top and i have to scroll down every time. Is there any way i can make the content place holder as the starting display point for my webpage?? Thanks in advance.

2 Answers2

0

Add an HTML anchor in the view where the you want to be scrolled down to. Then on page load use java script to move to the anchor. see How to scroll HTML page to given anchor using jQuery or Javascript?

Here is an example assuming you are using Razor with a section render

<a href="#contentAnchor">
   @RenderSection("content")
</a>

<script type="text/javascript">
    $(function() {
         location.hash = "#contentAnchor";
     });
</script>
Community
  • 1
  • 1
CharlesNRice
  • 3,219
  • 1
  • 16
  • 25
  • You don't need to use Javascript. You can just open the page at the anchor using URL#anchorName. Define the anchor like this: – David Apr 20 '14 at 15:06
  • That's if he has control over the page request. Seems like he just has the URL and wants to move it programmatically to an anchor spot. He could do Request.Redirect to the hash but that would cause two web request hits. – CharlesNRice Apr 20 '14 at 15:11
0

Assuming you are using asp.net web forms, you can use below snippet to set the focus on your placeholder/server control,

if (!IsPostBack)
{
    Page.SetFocus(ContentPlaceHolderID);
}
Palak Bhansali
  • 731
  • 4
  • 10