How to hide a query string parameter in the url

Noel picture Noel · May 16, 2011 · Viewed 14.6k times · Source

I've a panel bar with some items in it. When I right click on the items and if I select "open in new tab", I need to open the link in a new tab. For eg. if my page is "http:localhost/MyPage" My grid is:

Name

  • abc
  • bcd
  • cde

When I click on the second item, the navigateUrl would be "http:localhost/MyPage/?Name=bcd"

This works fine. But I want to hide the name in the url. Is there any other way, I can pass the name to next page without exposing it in the url. I could use sessions, but unfortunately, I cannot write it as a code for the default context menu.

Answer

TheVillageIdiot picture TheVillageIdiot · May 16, 2011

You can use LinkButton objects. They will postback and then you can redirect requests to desired pages.

ASPX:

<asp:linkbutton id="lnkabcd" runat="server" text="abcd" onclick="lnkabcd_clicked"/>

C#:

public void linkabcd_clicked(object sender, EventArgs e)
{
    Response.Redirect("URL OF TARGET PAGE");
}

Ofcourse it will be very cumbersome if you have lot of links. You can use grid (hope you are using it as you write in your question) and catch row event with command name and command argument properties.

To hide the url in addressbar of the browser, you need to do URL rewriting. For more on URL rewriting please visit these pages on codeproject and msdn.