Asp.net - scroll goes to the top when redirecting querystring

115 Views Asked by At

I have a page with 100 products. When the product is clicked, I add the product info to the cart with session.

I'm sending the id of the product to the session with the querystring.

response.redirect("shop.aspx?id=2")

When the user clicks on the product, my page is refreshed because it sends a querystring to the page and the page position goes to the top.

MaintainScrollPositionOnPostback="true"

not work for me cause i use response.redirect();

thats my problem. Thanks all =(

1

There are 1 best solutions below

1
On

I explain the solution.

if u guys using ' html a tag or Response.Redirect() ' Delete all.

use PostBackUrl

<asp:Button ID="Button1" PostBackUrl="~/WebForm1.aspx?id=3" runat="server" Text="Submit" />

At the top of your .aspx codefile, insert the following:

 MaintainScrollPositionOnPostback="true"

Like this

<%@ Page Language="C#" MaintainScrollPositionOnPostback="true" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"

Thats all <asp:Button ID="Button1" PostBackUrl="WebForm1.aspx?id=<%#Eval(id)%>" runat="server" Text="Submit" />

I wish you good work