0

is there a way to scroll-down to a particular div when the page loads? i have 100+ rows so when the page loads i am highlighting the div background based on certain conditions so same way is that possible to position to the particular div?

i am using a repeater with

<asp:Repeater EnableViewState="true" ID="rpt" runat="server" OnItemDataBound="rpt_ItemDataBound">       
        <ItemTemplate>
            <div style='padding: 10px;' id="mydiv"  runat="server">
                <div>
                    <asp:Label runat="server" ID="lblName" Text='<%# Eval("Name") %>'> </asp:Label>
                </div>  
            </div>
        </ItemTemplate> 
    </asp:Repeater> 

protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
   if (......)
         mydiv.Attributes.Add("class", "selected_div");
}
Nick Kahn
  • 19,652
  • 91
  • 275
  • 406
  • checkout this link: http://stackoverflow.com/questions/1094589/maintain-scroll-position-of-a-div-within-a-page-on-postback – Ashwini Verma Jun 01 '12 at 05:48

2 Answers2

0

Use tabindex property of div. set the focus of div using tab-index.

check this link : Set keyboard focus to a <div>

Community
  • 1
  • 1
Jagz W
  • 855
  • 3
  • 12
  • 28
0

If you are using jquery, you could use the scrollTo plugin, on the page's ready function, using your "selected_div" class as selector. Such as:

$(document).ready(function() {
  $(document).scrollTo('.selected_div');
} 

Without jquery you can use the standard javascript function .scrollIntoView(true) on the div element. However, you'd have to locate the element first, in order to call that function.

A combination of both is also valid. Using jquery to locate the selected div using your class selector, and on the element calling .scrollIntoView(true).

Pablo Romeo
  • 11,298
  • 2
  • 30
  • 58