Search code examples
c#asp.netjquery-uiinternet-explorer-7jquery-ui-tabs

Response.Redirect with # anchor, does not work in IE7


Response.Redirect(string.Format("myprofile.aspx?uid={0}&result=saved#main",user.UserID));

said code translates to

IE7 - myprofile.aspx?uid=933fdf8e-1be0-4bc2-a269-ac0b01ba4755&result=saved

FF- myprofile.aspx?uid=933fdf8e-1be0-4bc2-a269-ac0b01ba4755&result=saved#main

why does IE7 drop my anchor?

edit: I should mention I am using this in conjunction with jQuery UI's tab control. I want the postback to tab into a specific tab.


Solution

  • It would be quite the hack, but if IE isn't behaving, you could do this.

    pass a param as well, e.g.

    uid=933fdf8e-1be0-4bc2-a269-ac0b01ba4755&result=saved&hash=main#main
    

    Then on your page (before the body close tag, or as an onload event), only for IE, extract the parameter if present and set the hash manually.

    <!--[if IE]>
    <script>
      if(document.location.href.indexOf('&hash=') != -1){
        //extract value from url...
        document.location.hash = extractedValue;
      }
    </script>
    <![endif]-->