Click here to Skip to main content
15,354,460 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a project in c# where I have used Response.Redirect to jump to another part of the page with the hash-tag (#) in the url - but the problem is that Response.Redirect creates an item in the browserhistory - and I want to avoid this item. I have tried to do it with a javascript function - but the browser creates a historyitem anyway.

I have tried to avoid Response.Redirect with the following codesnippet.

The code has been made it in with javascript.

Until now I have googlet and searched without finding the right solution...

Is it possible to avoid this browseritem in the browserhistory under those circumstances?

Regards Michael

What I have tried:

In my markup I have made the following:
<asp:ImageButton ID="btnDelAccounting" runat="server" PostBackUrl="#DelAccounting" OnClientClick="ShowDialog('DelAccounting');"/>

In my javascript function I have made the following:
function ShowDialog(hash) {
    window.location.replace('Accounting.aspx#' + hash);
Updated 27-Oct-21 0:12am

1 solution

You need to prevent the image button from causing a postback to the sever.

<asp:ImageButton ID="btnDelAccounting" runat="server" OnClientClick="ShowDialog('DelAccounting');return false;"/>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900