3

Some users who navigate to my page do so via an url like this : http://domain/ProductDetail.aspx?Productid=123#Pricing

In this section is a asp:button to make a purchase. This button cause a postback, and when the page rerendering in the broswer the FragmentIdentifier #Pricing is still in the address window.

This is causing problems because there is new content rendered on the page which isn't visible if the browser navigates to the #Pricing section.

How do I prevent the FragmentIdentifier on postback?

Clarification: It appears that this problem happens in Chrome but does not happen in IE8 or FireFox. Chrome holds on to the #FragmentIdentifier after postback even those there is no reference to it in the action attribute.

Aheho
  • 12,622
  • 13
  • 54
  • 83
  • It's not called a "hashtag" (that's a Twitter term). In HTML and in URIs it's called a "fragment identifier". – Dai Jul 16 '12 at 18:43
  • I've edited the question to correct the terminology – Aheho Jul 16 '12 at 18:46
  • "navigates to the #Pricing section" isn't a postback. – rick schott Jul 16 '12 at 18:47
  • That's not what I'm saying. The user navigates from Summary.aspx to ProductDetail.aspx?ProductID=123#Pricing. Once they are on the ProductDetail.aspx page, they click a button that causes a postback. – Aheho Jul 16 '12 at 18:50

4 Answers4

2

You can't, browser doesn't send it:

When a URI reference is used to perform a retrieval action on the identified resource, the optional fragment identifier, separated from the URI by a crosshatch ("#") character, consists of additional reference information to be interpreted by the user agent after the retrieval action has been successfully completed. As such, it is not part of a URI, but is often used in conjunction with a URI.

How to get Url Hash (#) from server side

Community
  • 1
  • 1
rick schott
  • 21,012
  • 5
  • 52
  • 81
  • The browser may not send it but Chrome is preserving the #Pricing reference across postbacks even though it isn't referenced in the
    attribute.
    – Aheho Jul 16 '12 at 19:10
0

You can force the browser to get rid of the # tag by redirecting to the same page.

DreamTeK
  • 32,537
  • 27
  • 112
  • 171
nunespascal
  • 17,584
  • 2
  • 43
  • 46
0

Browsers don't send URL fragments on the server side. You can't modify them the only option you can try is URL rewrite, if that helps. good luck...

Scorpio
  • 1,151
  • 1
  • 19
  • 37
0

The ASP.NET engine will cause a simple submit without any given URL, so the browser is forced to take the URL of the current page.

You can get rid of the hash after the postback by hooking a self executing javascript into the HTML that will replace the hash to an empty string.

Here is an example:

if(this.Page.IsPostback)
{
    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "RemoveHash", "window.location.hash=''", true);
}
Martin Braun
  • 10,906
  • 9
  • 64
  • 105