2

I am using ASP.NET web forms to design a site. One of the pages uses a <DIV> to hold a scrolling list of asp:ImageButton controls, each of which displays an image. The goal is to be able to display a long list of images inside a scrollable DIV tag, making it easier for the user to choose one without using a third-party control and avoiding controls that require paging. Here's a sample of the DIV I've built:

<div id="divOne" runat="server" style="height: 230px; width: 330px; overflow: auto;text-align: center;">
    <asp:ImageButton runat="server" ImageUrl="../Images/image1_small.jpg" AlternateText="Image #1" CommandArgument="Image #1" OnClick="ImagePicked" /><br />
    <asp:ImageButton runat="server" ImageUrl="../Images/image2_small.jpg" AlternateText="Image #2" CommandArgument="Image #2" OnClick="ImagePicked" /><br />
    ...
 </div>

When the user clicks an image, it triggers an action to update another part of the page. But the problem is that when the image is clicked and the action fires, the list of images resets back to the first one at the top of the list. I tried using an UpdatePanel to control this, but it still happens. Is there any way to prevent the list of images from resetting?

Daniel Anderson
  • 275
  • 3
  • 16

1 Answers1

1

If you just want to save scroll position after postback, there are several ways to do it. The simplest one is to save scroll position with javascript whenever onscroll event triggers, then restore saved value on page load, as shown here: Maintain scroll position of a div within a page on postback

If that doesn't quite work for you, you can try storing scroll position in a hidden field (see this answer: https://stackoverflow.com/a/1184659/1202275). Some also suggest to store it in a cookie, but that can backfire if a person using the page has cookies disabled for any reason.

Hope that helps!

Community
  • 1
  • 1
Darth Veyda
  • 828
  • 2
  • 12
  • 23