My page contains datalist that renders small thumbnails of 90 x 70. When i click on thumbnail a large copy of thumbnail in an image control above the datalist is displayed.The problem is page goes to top of its scroll position.I have to scorll down to get to thumbnail.How can i maintain scrolling position of my page?

<asp:Image ID="imgCarPhoto" runat="server" Height="300px" Width="385px" />&nbsp;<asp:DataList ID="dlstCarPhotos" runat="server" RepeatDirection="Horizontal" RepeatColumns="4">
					<ItemTemplate>
						<a href="#" runat="server" id="lnkPreviewImage">
							<asp:Image ID="imgCar" runat="server" ImageUrl='<%#Eval("PictureID","UserControls/imageByPID.ashx?pid={0}")%>'
								Width="90" Height="70" AlternateText="" />
						</a>
					</ItemTemplate>
				</asp:DataList>

Recommended Answers

All 3 Replies

Does your page getting postback when you click the image link?

If so, set the Page.MaintainScrollPositionOnPostBack Property to true to to return the user to the same position in the client browser after postback.

No my page didnot postback.

i use following code to prevent page from postback.

Protected Sub dlstCarPhotos_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlstCarPhotos.ItemDataBound
        Try
            CType(e.Item.FindControl("lnkPreviewImage"), HtmlAnchor).Attributes.Add("onClick", "javascript:document.getElementById('" & imgCarPhoto.ClientID & "').src = '" & CType(e.Item.FindControl("imgCar"), System.Web.UI.WebControls.Image).ImageUrl.ToString & "'; ")

        Catch ex As Exception
            lblerror.Text = ex.Message
       End Try
	End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.