468,290 Members | 2,104 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,290 developers. It's quick & easy.

After PostBack - back to same place on page

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
Nov 18 '05 #1
13 4902
I don't know of any way to do this automatically in .NET.

However, you could capture the mouse position in client-side javascript,
post to the server in a hidden field, let the server handle its
processing then post-render on the client, have the page reposition
itself based on the last mouse position.

--Jason

tshad wrote:
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

Nov 18 '05 #2
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

Nov 18 '05 #3
Their solutions are nice, otherwise you could always just enable
SmartNavigation on your pages.

-Brian

"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

Nov 18 '05 #4
Check out these article,
http://aspalliance.com/aldotnet/exam...utoscroll.aspx
http://www.dotnetjunkies.com/howto/default.aspx?id=38
--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"tshad" <ts**********@ftsolutions.com> wrote in message
news:#1**************@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

Nov 18 '05 #5
"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:u6****************@TK2MSFTNGP14.phx.gbl...
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="" />

I tried that as it looks like a pretty good solution.

The problem is I get the following error:
************************************************** *************************************
Compiler Error Message: BC30311: Value of type 'System.Web.HttpRequest'
cannot be converted to 'Boolean'.

Source Error:

Line 198:</head>
Line 199:<%
Line 200: if (Request["__SCROLLPOS"] != null &&
Line 201: Request["__SCROLLPOS"] != String.Empty) {
Line 202: int pos = Convert.ToInt32 (Request["__SCROLLPOS"]);

************************************************** *************************************

Here is the piece I just cut out of the linked page put in place of the
<body> statement:
************************************************** **************************************
<%
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;\">");
}
%>
************************************************** ***************************************

and here is the hidden object which I put right after the <form
runat="server"> line:

<input type="hidden" name="__SCROLLPOS" value="" />

Am I missing something?

Thanks,

Tom ================================================== ==========================
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


Nov 18 '05 #6
"Saravana" <sa******@sct.co.in> wrote in message
news:Nk***************@news.cpqcorp.net...
Check out these article,
http://aspalliance.com/aldotnet/exam...utoscroll.aspx
http://www.dotnetjunkies.com/howto/default.aspx?id=38

This looks like a pretty good solution, but I get the following error trying
to execute it:
************************************************** ***********************
Compiler Error Message: BC30451: Name 'BindData' is not declared.

Source Error:

Line 30:
Line 31: if not IsPostBack then
Line 32: Call BindData()
Line 33: else
Line 34: Dim startUpScript As String
************************************************** *****************

I found that the setting of the string is what is causing it. I pared down
the line to only:

startUpScript = "<script language=Javascript></script>"

And I still get the error. I get the error if I take out the
Me.RegisterStartupScript line also.

Here is the code now:

************************************************** ******************
if not IsPostBack then
Call BindData()
else
Dim startUpScript As String
startUpScript = "<script language=Javascript></script>"
end if
************************************************** *******************************

If I change it to something like:

startUpScript = "This is a test"

It works fine.

I am getting the error on the initial load of the page, so the string setup
isn't even done yet.

What am I missing???

Thanks,

Tom.

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"tshad" <ts**********@ftsolutions.com> wrote in message
news:#1**************@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


Nov 18 '05 #7
"Saravana" <sa******@sct.co.in> wrote in message
news:Nk***************@news.cpqcorp.net...
Check out these article,
http://aspalliance.com/aldotnet/exam...utoscroll.aspx
http://www.dotnetjunkies.com/howto/default.aspx?id=38
I tried that but got the following error:

Page Cannot Be Found
We apologize for the inconvenience, but the page you are seeking cannot be
found in this location.
Is this the document you are looking for? Int32 - 38 - Object reference not
set to an instance of an object.

Tom


--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"tshad" <ts**********@ftsolutions.com> wrote in message
news:#1**************@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


Nov 18 '05 #8
Check out this link, this should work.
http://www.dotnetjunkies.com/Tutoria...E6AF9052D.dcik
http://www.dotnetjunkies.com/HowTo/5...0CA019FDD.dcik

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"tshad" <ts**********@ftsolutions.com> wrote in message
news:uJ**************@TK2MSFTNGP10.phx.gbl...
"Saravana" <sa******@sct.co.in> wrote in message
news:Nk***************@news.cpqcorp.net...
Check out these article,
http://aspalliance.com/aldotnet/exam...utoscroll.aspx
http://www.dotnetjunkies.com/howto/default.aspx?id=38
I tried that but got the following error:

Page Cannot Be Found
We apologize for the inconvenience, but the page you are seeking cannot be
found in this location.
Is this the document you are looking for? Int32 - 38 - Object reference

not set to an instance of an object.

Tom


--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"tshad" <ts**********@ftsolutions.com> wrote in message
news:#1**************@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



Nov 18 '05 #9
OK - here is the VB.Net code I use:

If Not (Request("__SCROLLPOS") Is Nothing) AndAlso Request("__SCROLLPOS")
<> String.Empty Then
Dim pos As Integer = Convert.ToInt32(Request("__SCROLLPOS"))
.Attributes("onscroll") =
"javascript:if(document.forms[0].__SCROLLPOS)document.forms[0].__SCROLLPOS.value
= Body.scrollTop;"
.Attributes("onload") = "javascript:Body.scrollTop=" & pos & ";"
Else
.Attributes("onscroll") =
"javascript:if(document.forms[0].__SCROLLPOS)document.forms[0].__SCROLLPOS.value
= Body.scrollTop;"
End If

--
Joe Fallon


"tshad" <ts**********@ftsolutions.com> wrote in message
news:uM**************@TK2MSFTNGP14.phx.gbl...
"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:u6****************@TK2MSFTNGP14.phx.gbl...
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="" />


I tried that as it looks like a pretty good solution.

The problem is I get the following error:
************************************************** *************************************
Compiler Error Message: BC30311: Value of type 'System.Web.HttpRequest'
cannot be converted to 'Boolean'.

Source Error:

Line 198:</head>
Line 199:<%
Line 200: if (Request["__SCROLLPOS"] != null &&
Line 201: Request["__SCROLLPOS"] != String.Empty) {
Line 202: int pos = Convert.ToInt32 (Request["__SCROLLPOS"]);

************************************************** *************************************

Here is the piece I just cut out of the linked page put in place of the
<body> statement:
************************************************** **************************************
<%
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;\">");
}
%>
************************************************** ***************************************

and here is the hidden object which I put right after the <form
runat="server"> line:

<input type="hidden" name="__SCROLLPOS" value="" />

Am I missing something?

Thanks,

Tom
================================================== ==========================
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



Nov 18 '05 #10
"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
OK - here is the VB.Net code I use:

If Not (Request("__SCROLLPOS") Is Nothing) AndAlso Request("__SCROLLPOS")
<> String.Empty Then
Dim pos As Integer = Convert.ToInt32(Request("__SCROLLPOS"))
.Attributes("onscroll") =
"javascript:if(document.forms[0].__SCROLLPOS)document.forms[0].__SCROLLPOS.value
= Body.scrollTop;"
.Attributes("onload") = "javascript:Body.scrollTop=" & pos & ";"
Else
.Attributes("onscroll") =
"javascript:if(document.forms[0].__SCROLLPOS)document.forms[0].__SCROLLPOS.value
= Body.scrollTop;"
End If
My mistake.

I hadn't realized it wasn't VB.Net (brain fade).

However, I am still getting an error on the ".Attributes". It is
complaining that their is no "With" statement.

Tom
--
Joe Fallon


"tshad" <ts**********@ftsolutions.com> wrote in message
news:uM**************@TK2MSFTNGP14.phx.gbl...
"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:u6****************@TK2MSFTNGP14.phx.gbl...
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="" />


I tried that as it looks like a pretty good solution.

The problem is I get the following error:
************************************************** *************************************
Compiler Error Message: BC30311: Value of type 'System.Web.HttpRequest'
cannot be converted to 'Boolean'.

Source Error:

Line 198:</head>
Line 199:<%
Line 200: if (Request["__SCROLLPOS"] != null &&
Line 201: Request["__SCROLLPOS"] != String.Empty) {
Line 202: int pos = Convert.ToInt32 (Request["__SCROLLPOS"]);

************************************************** *************************************

Here is the piece I just cut out of the linked page put in place of the
<body> statement:
************************************************** **************************************
<%
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;\">");
}
%>
************************************************** ***************************************

and here is the hidden object which I put right after the <form
runat="server"> line:

<input type="hidden" name="__SCROLLPOS" value="" />

Am I missing something?

Thanks,

Tom
================================================== ==========================
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



Nov 18 '05 #11
I use code to find the HTML body.
That is what the .Attributes are added to.

With HTML_Body
--
Joe Fallon


"tshad" <ts**********@ftsolutions.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
OK - here is the VB.Net code I use:

If Not (Request("__SCROLLPOS") Is Nothing) AndAlso Request("__SCROLLPOS")
<> String.Empty Then
Dim pos As Integer = Convert.ToInt32(Request("__SCROLLPOS"))
.Attributes("onscroll") =
"javascript:if(document.forms[0].__SCROLLPOS)document.forms[0].__SCROLLPOS.value
= Body.scrollTop;"
.Attributes("onload") = "javascript:Body.scrollTop=" & pos & ";"
Else
.Attributes("onscroll") =
"javascript:if(document.forms[0].__SCROLLPOS)document.forms[0].__SCROLLPOS.value
= Body.scrollTop;"
End If


My mistake.

I hadn't realized it wasn't VB.Net (brain fade).

However, I am still getting an error on the ".Attributes". It is
complaining that their is no "With" statement.

Tom

--
Joe Fallon


"tshad" <ts**********@ftsolutions.com> wrote in message
news:uM**************@TK2MSFTNGP14.phx.gbl...
"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:u6****************@TK2MSFTNGP14.phx.gbl...
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="" />
I tried that as it looks like a pretty good solution.

The problem is I get the following error:
************************************************** *************************************
Compiler Error Message: BC30311: Value of type 'System.Web.HttpRequest'
cannot be converted to 'Boolean'.

Source Error:

Line 198:</head>
Line 199:<%
Line 200: if (Request["__SCROLLPOS"] != null &&
Line 201: Request["__SCROLLPOS"] != String.Empty) {
Line 202: int pos = Convert.ToInt32 (Request["__SCROLLPOS"]);

************************************************** *************************************

Here is the piece I just cut out of the linked page put in place of the
<body> statement:
************************************************** **************************************
<%
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;\">");
}
%>
************************************************** ***************************************

and here is the hidden object which I put right after the <form
runat="server"> line:

<input type="hidden" name="__SCROLLPOS" value="" />

Am I missing something?

Thanks,

Tom
================================================== ==========================
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
>



Nov 18 '05 #12
"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:er**************@TK2MSFTNGP14.phx.gbl...
I use code to find the HTML body.
That is what the .Attributes are added to.

With HTML_Body
You lost me on that one.

Tom. --
Joe Fallon


"tshad" <ts**********@ftsolutions.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
OK - here is the VB.Net code I use:

If Not (Request("__SCROLLPOS") Is Nothing) AndAlso
Request("__SCROLLPOS") <> String.Empty Then
Dim pos As Integer = Convert.ToInt32(Request("__SCROLLPOS"))
.Attributes("onscroll") =
"javascript:if(document.forms[0].__SCROLLPOS)document.forms[0].__SCROLLPOS.value
= Body.scrollTop;"
.Attributes("onload") = "javascript:Body.scrollTop=" & pos &
";"
Else
.Attributes("onscroll") =
"javascript:if(document.forms[0].__SCROLLPOS)document.forms[0].__SCROLLPOS.value
= Body.scrollTop;"
End If


My mistake.

I hadn't realized it wasn't VB.Net (brain fade).

However, I am still getting an error on the ".Attributes". It is
complaining that their is no "With" statement.

Tom

--
Joe Fallon


"tshad" <ts**********@ftsolutions.com> wrote in message
news:uM**************@TK2MSFTNGP14.phx.gbl...
"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:u6****************@TK2MSFTNGP14.phx.gbl...
> 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="" />
>

I tried that as it looks like a pretty good solution.

The problem is I get the following error:
************************************************** *************************************
Compiler Error Message: BC30311: Value of type 'System.Web.HttpRequest'
cannot be converted to 'Boolean'.

Source Error:

Line 198:</head>
Line 199:<%
Line 200: if (Request["__SCROLLPOS"] != null &&
Line 201: Request["__SCROLLPOS"] != String.Empty) {
Line 202: int pos = Convert.ToInt32 (Request["__SCROLLPOS"]);

************************************************** *************************************

Here is the piece I just cut out of the linked page put in place of the
<body> statement:
************************************************** **************************************
<%
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;\">");
}
%>
************************************************** ***************************************

and here is the hidden object which I put right after the <form
runat="server"> line:

<input type="hidden" name="__SCROLLPOS" value="" />

Am I missing something?

Thanks,

Tom
> ================================================== ==========================
> 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
>>
>
>



Nov 18 '05 #13
rwoeke
11
Page MaintainScrollPositionOnPostback ="true" for .net 2 works like a charm
Jul 13 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Guadala Harry | last post: by
4 posts views Thread by Mad Scientist Jr | last post: by
13 posts views Thread by Chris Thunell | last post: by
21 posts views Thread by Martin Eyles | last post: by
10 posts views Thread by Robert | last post: by
1 post views Thread by Louis-Philippe Dumoulin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.