ASP.NET postbacks lose the hash in the URL

后端 未结 3 989
再見小時候
再見小時候 2021-02-20 02:14

On an ASP.NET page with a tabstrip, I\'m using the hash code in the URL to keep track of what tab I\'m on (using the BBQ jQuery plugin). For example:

http://mysi         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-20 03:06

    The problem is that the postback goes to the url of the current page, which is set in the action of the form on the page. By default this url is without #hash in asp.net, and its automatically set by asp.net, you have no control over it.

    You could add the #hash to the forms action attribute with javascript:

    document.getElementById("aspnetForm").action += location.hash
    

    or, if updating an action with a hash already in it:

    var form = document.getElementById("aspnetForm");
    form.action = form.action.split('#')[0] + location.hash
    

    just make sure you execute this code on window.load and you target the right ID

提交回复
热议问题