Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Restore scroll position of a DIV over a postback

Reply
Thread Tools

Restore scroll position of a DIV over a postback

 
 
JezB
Guest
Posts: n/a
 
      07-05-2004
There are a few references on the net about how to restore a page's scroll
position over a postback. This is a simple one which works for me:
eg. http://www.devhood.com/messages/mess...read_id=104625

My question is : can the same thing be done to restore the scroll position
of a specific DIV within a page? I have a DIV section which scrolls
independently to the page :
<div style="vertical-align: top; height:200px; width:100%; overflow:auto;">
<aspataGrid runat="server" ...>
...
</aspataGrid>
</div>
On each postback it is scrolling back to the top. Very annoying to the user
if it's a click within the scroll area that causes the postback.

Could someone tell me how? My knowledge of javascript is almost zero.


 
Reply With Quote
 
 
 
 
JezB
Guest
Posts: n/a
 
      07-05-2004
Never mind. I found a way. For the record:

<body onload="javascript:scrollTo('scrollArea')" >
<form id="Form1" method="post" runat="server">
...
<div id="scrollArea onscroll="javascript:setScroll(this);"
runat="server" style="vertical-align: top; height:200px; width:100%;
overflow:auto;">
<aspataGrid runat="server" ...>
...
</aspataGrid>
</div>
<input type="hidden" id="scrollPos" name="scrollPos" value="0"
runat="server">
...
</form>
<script language="javascript">
function setScroll(val) {
document.Form1.scrollPos.value = val.scrollTop;
}
function scrollTo(what) {
document.getElementById(what).scrollTop =
document.Form1.scrollPos.value;
}
</script>
</body>




"JezB" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> There are a few references on the net about how to restore a page's scroll
> position over a postback. This is a simple one which works for me:
> eg. http://www.devhood.com/messages/mess...read_id=104625
>
> My question is : can the same thing be done to restore the scroll position
> of a specific DIV within a page? I have a DIV section which scrolls
> independently to the page :
> <div style="vertical-align: top; height:200px; width:100%;

overflow:auto;">
> <aspataGrid runat="server" ...>
> ...
> </aspataGrid>
> </div>
> On each postback it is scrolling back to the top. Very annoying to the

user
> if it's a click within the scroll area that causes the postback.
>
> Could someone tell me how? My knowledge of javascript is almost zero.
>
>



 
Reply With Quote
 
 
 
 
MA
Guest
Posts: n/a
 
      07-05-2004
Or you could use:

Page.SmartNavigation = true;

/Marre

"JezB" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Never mind. I found a way. For the record:
>
> <body onload="javascript:scrollTo('scrollArea')" >
> <form id="Form1" method="post" runat="server">
> ...
> <div id="scrollArea onscroll="javascript:setScroll(this);"
> runat="server" style="vertical-align: top; height:200px; width:100%;
> overflow:auto;">
> <aspataGrid runat="server" ...>
> ...
> </aspataGrid>
> </div>
> <input type="hidden" id="scrollPos" name="scrollPos" value="0"
> runat="server">
> ...
> </form>
> <script language="javascript">
> function setScroll(val) {
> document.Form1.scrollPos.value = val.scrollTop;
> }
> function scrollTo(what) {
> document.getElementById(what).scrollTop =
> document.Form1.scrollPos.value;
> }
> </script>
> </body>
>
>
>
>
> "JezB" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > There are a few references on the net about how to restore a page's

scroll
> > position over a postback. This is a simple one which works for me:
> > eg. http://www.devhood.com/messages/mess...read_id=104625
> >
> > My question is : can the same thing be done to restore the scroll

position
> > of a specific DIV within a page? I have a DIV section which scrolls
> > independently to the page :
> > <div style="vertical-align: top; height:200px; width:100%;

> overflow:auto;">
> > <aspataGrid runat="server" ...>
> > ...
> > </aspataGrid>
> > </div>
> > On each postback it is scrolling back to the top. Very annoying to the

> user
> > if it's a click within the scroll area that causes the postback.
> >
> > Could someone tell me how? My knowledge of javascript is almost zero.
> >
> >

>
>



 
Reply With Quote
 
JezB
Guest
Posts: n/a
 
      07-05-2004
Well, I did try that first, obviously.
But it didn't work.

"MA" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Or you could use:
>
> Page.SmartNavigation = true;
>
> /Marre
>
> "JezB" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Never mind. I found a way. For the record:
> >
> > <body onload="javascript:scrollTo('scrollArea')" >
> > <form id="Form1" method="post" runat="server">
> > ...
> > <div id="scrollArea onscroll="javascript:setScroll(this);"
> > runat="server" style="vertical-align: top; height:200px; width:100%;
> > overflow:auto;">
> > <aspataGrid runat="server" ...>
> > ...
> > </aspataGrid>
> > </div>
> > <input type="hidden" id="scrollPos" name="scrollPos" value="0"
> > runat="server">
> > ...
> > </form>
> > <script language="javascript">
> > function setScroll(val) {
> > document.Form1.scrollPos.value = val.scrollTop;
> > }
> > function scrollTo(what) {
> > document.getElementById(what).scrollTop =
> > document.Form1.scrollPos.value;
> > }
> > </script>
> > </body>
> >
> >
> >
> >
> > "JezB" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > There are a few references on the net about how to restore a page's

> scroll
> > > position over a postback. This is a simple one which works for me:
> > > eg.

http://www.devhood.com/messages/mess...read_id=104625
> > >
> > > My question is : can the same thing be done to restore the scroll

> position
> > > of a specific DIV within a page? I have a DIV section which scrolls
> > > independently to the page :
> > > <div style="vertical-align: top; height:200px; width:100%;

> > overflow:auto;">
> > > <aspataGrid runat="server" ...>
> > > ...
> > > </aspataGrid>
> > > </div>
> > > On each postback it is scrolling back to the top. Very annoying to the

> > user
> > > if it's a click within the scroll area that causes the postback.
> > >
> > > Could someone tell me how? My knowledge of javascript is almost zero.
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
JezB
Guest
Posts: n/a
 
      07-05-2004
Well, it did work partly : if the control which causes the postback is in
the scrollable DIV it does rescroll far enough to focus on it if I turn
smart navigation on, but not EXACTLY to the same scroll position (so user
sees it jump from middle to bottom, for example). Also, if the control which
caused the postback was outside the scrollable area it always scrolled
itself back to the top. Therefore I had to come up with a better solution.

"JezB" <(E-Mail Removed)> wrote in message
news:u$(E-Mail Removed)...
> Well, I did try that first, obviously.
> But it didn't work.
>
> "MA" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Or you could use:
> >
> > Page.SmartNavigation = true;
> >
> > /Marre
> >
> > "JezB" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Never mind. I found a way. For the record:
> > >
> > > <body onload="javascript:scrollTo('scrollArea')" >
> > > <form id="Form1" method="post" runat="server">
> > > ...
> > > <div id="scrollArea onscroll="javascript:setScroll(this);"
> > > runat="server" style="vertical-align: top; height:200px; width:100%;
> > > overflow:auto;">
> > > <aspataGrid runat="server" ...>
> > > ...
> > > </aspataGrid>
> > > </div>
> > > <input type="hidden" id="scrollPos" name="scrollPos" value="0"
> > > runat="server">
> > > ...
> > > </form>
> > > <script language="javascript">
> > > function setScroll(val) {
> > > document.Form1.scrollPos.value = val.scrollTop;
> > > }
> > > function scrollTo(what) {
> > > document.getElementById(what).scrollTop =
> > > document.Form1.scrollPos.value;
> > > }
> > > </script>
> > > </body>
> > >
> > >
> > >
> > >
> > > "JezB" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > There are a few references on the net about how to restore a page's

> > scroll
> > > > position over a postback. This is a simple one which works for me:
> > > > eg.

> http://www.devhood.com/messages/mess...read_id=104625
> > > >
> > > > My question is : can the same thing be done to restore the scroll

> > position
> > > > of a specific DIV within a page? I have a DIV section which scrolls
> > > > independently to the page :
> > > > <div style="vertical-align: top; height:200px; width:100%;
> > > overflow:auto;">
> > > > <aspataGrid runat="server" ...>
> > > > ...
> > > > </aspataGrid>
> > > > </div>
> > > > On each postback it is scrolling back to the top. Very annoying to

the
> > > user
> > > > if it's a click within the scroll area that causes the postback.
> > > >
> > > > Could someone tell me how? My knowledge of javascript is almost

zero.
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Edward
Guest
Posts: n/a
 
      07-05-2004
try this one, http://www.strengthtechnologies.com/scroll/

someone answered in this newsgroup, I tried it just now, it works very well,
except a bit shake in the page.

hope it's exciting for you.

> Well, it did work partly : if the control which causes the postback is in
> the scrollable DIV it does rescroll far enough to focus on it if I turn
> smart navigation on, but not EXACTLY to the same scroll position (so user
> sees it jump from middle to bottom, for example). Also, if the control

which
> caused the postback was outside the scrollable area it always scrolled
> itself back to the top. Therefore I had to come up with a better solution.
>
> "JezB" <(E-Mail Removed)> wrote in message
> news:u$(E-Mail Removed)...
> > Well, I did try that first, obviously.
> > But it didn't work.
> >
> > "MA" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Or you could use:
> > >
> > > Page.SmartNavigation = true;
> > >
> > > /Marre
> > >
> > > "JezB" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > Never mind. I found a way. For the record:
> > > >
> > > > <body onload="javascript:scrollTo('scrollArea')" >
> > > > <form id="Form1" method="post" runat="server">
> > > > ...
> > > > <div id="scrollArea onscroll="javascript:setScroll(this);"
> > > > runat="server" style="vertical-align: top; height:200px; width:100%;
> > > > overflow:auto;">
> > > > <aspataGrid runat="server" ...>
> > > > ...
> > > > </aspataGrid>
> > > > </div>
> > > > <input type="hidden" id="scrollPos" name="scrollPos"

value="0"
> > > > runat="server">
> > > > ...
> > > > </form>
> > > > <script language="javascript">
> > > > function setScroll(val) {
> > > > document.Form1.scrollPos.value = val.scrollTop;
> > > > }
> > > > function scrollTo(what) {
> > > > document.getElementById(what).scrollTop =
> > > > document.Form1.scrollPos.value;
> > > > }
> > > > </script>
> > > > </body>
> > > >
> > > >
> > > >
> > > >
> > > > "JezB" <(E-Mail Removed)> wrote in message
> > > > news:(E-Mail Removed)...
> > > > > There are a few references on the net about how to restore a

page's
> > > scroll
> > > > > position over a postback. This is a simple one which works for me:
> > > > > eg.

> > http://www.devhood.com/messages/mess...read_id=104625
> > > > >
> > > > > My question is : can the same thing be done to restore the scroll
> > > position
> > > > > of a specific DIV within a page? I have a DIV section which

scrolls
> > > > > independently to the page :
> > > > > <div style="vertical-align: top; height:200px; width:100%;
> > > > overflow:auto;">
> > > > > <aspataGrid runat="server" ...>
> > > > > ...
> > > > > </aspataGrid>
> > > > > </div>
> > > > > On each postback it is scrolling back to the top. Very annoying to

> the
> > > > user
> > > > > if it's a click within the scroll area that causes the postback.
> > > > >
> > > > > Could someone tell me how? My knowledge of javascript is almost

> zero.
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to: set div scroll position on page load Mel ASP .Net 3 06-22-2009 11:07 PM
Using a div with scroll bars - can we get the scroll bars on the left instead of the right side? UJ ASP .Net 1 11-01-2006 09:32 PM
Restore scroll position of a DIV over a postback JezB ASP .Net 5 07-05-2004 02:27 PM
Restore scroll position of a DIV over postbacks JezB ASP .Net 1 07-02-2004 04:31 PM
Saving scroll position on a nested div? Greg Hurlman ASP .Net Building Controls 0 09-23-2003 03:25 PM



Advertisments