tags:

views:

707

answers:

3

I've a asp.net datagrid which shows customer order details. Pagination at the bottom of the grid is done using datalist and asp.net Linkbutton controls. Here is the code:

 <asp:DataList ID="DataList2" runat="server" CellPadding="1" CellSpacing="1" OnItemCommand="DataList2_ItemCommand"
                                        OnItemDataBound="DataList2_ItemDataBound" RepeatDirection="Horizontal">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lnkbtnPaging" runat="server" CommandArgument='<%# Eval("PageIndex") %>'
                                                CommandName="lnkbtnPaging" Text='<%# Eval("PageText") %>'></asp:LinkButton>
                                            <asp:Label runat="server" ID="lblPageSeparator" Text=" | " name=></asp:Label>
                                        </ItemTemplate>
                                    </asp:DataList>

When the user clicks on any page number(ie.Link button), I need to set focus on top of the page. How do i do this?

Thanks!

+1  A: 

You could try setting a named anchor at the top of the page. Here is an article that explains it http://www.w3schools.com/HTML/html_links.asp

Jacob Adams
named anchor does not seem to work with asp.net Linkbutton
if that is the case, you could always just uses standard html which is only another line of markup. This like the linkbutton, label, hyperlink, and table controls in ASP.NET are better off being replaced by html anyway, in my opinion
Jacob Adams
+1  A: 

I think the default behaviour would be for the page scroll position to be set back to the top of the page. Is there anything else in your page that might be overriding this behaviour?

For example:

  1. Is your DataList inside an UpdatePanel? In that case the current scroll position will be maintained over a (partial) post-back. You would therefore need to reset the scroll position to the top of the page yourself. One way to do this would be to implement a handler for the PageRequestManager's EndRequest client-side event which would set the scroll position - this thread explains how
  2. Is the Page MaintainScrollPositionOnPostBack property set to true?
Amal Sirisena
thanks a ton for ur inputs...:As suggested in point #1 above,following code worked for me!<script type="text/javascript"> Sys.WebForms.PageRequestManager.getInstance().add_endRequest(pageLoaded); function pageLoaded(sender, args) { window.scrollTo(0, 0); }</script>
A: 

<table width="10000000px"></table>

sdfsdf