Here is nice technique that I just implemented.
http://www.wintellect.com/resources/...aq_id=1&page=7
I put it in my Base Page so that every page that needs this functionality
has it if I add the HTML:
<input type="hidden" name="__SCROLLPOS" value="" />
================================================== ==========================
Is it possible to prevent a Web form from scrolling to the top of the page
when it posts back to the server?
================================================== ==========================
One way to do it is to add a SmartNavigation="true" attribute to the page's
@ Page directive. That requires Internet Explorer 5.0 or higher on the
client.
================================================== ==========================
To prevent unwanted scrolling in a wider range of browsers, you can use a
server-side script that generates client-side script.
The first step is to replace the page's <body> tag with the following
statements:
================================================== ==========================
<%
if (Request["__SCROLLPOS"] != null &&
Request["__SCROLLPOS"] != String.Empty) {
int pos = Convert.ToInt32 (Request["__SCROLLPOS"]);
Response.Write ("<body id=\"theBody\" " +
"onscroll=\"javascript
:document.forms[0].__SCROLLPOS.value = " +
"theBody.scrollTop;\" " +
"onload=\"javascript
:theBody.scrollTop=" + pos + ";\">");
}
else {
Response.Write ("<body id=\"theBody\" " +
"onscroll=\"javascript
:document.forms[0].__SCROLLPOS.value =" +
"theBody.scrollTop;\">");
}
%>
================================================== ==========================
Step two is to add the following line somewhere between the <form
runat="server"> and </form> tags:
================================================== ==========================
<input type="hidden" name="__SCROLLPOS" value="" />
================================================== ==========================
How does it work? The server-side script block outputs a <body> tag
containing an onscroll attribute that keeps tabs on the scroll position and
an onload attribute that restores the last scroll position following a
postback. The scroll position is transmitted to the server in a hidden
<input> control named __SCROLLPOS. Note that this technique is compatible
with Internet Explorer but not with Netscape Navigator.
================================================== ==========================
--
Joe Fallon
"tshad" <ts**********@ftsolutions.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I have some nested DataGrids in my Datalist. There could be 20 datalist
items.
If I scroll down to the 18th item and expand it to show the DataGrid, the
page always goes back to the beginning of the page instead of going back
to the same spot on the page or move the page up to show the grid.
Is there a way to have it go back to the place I left on the page?
Thanks,
Tom