1

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.

Noel
  • 83
  • 2
  • 2
  • 8
  • _Why_ would you want to hide it? As a power user, it might be an advantange to change the URL directly to get the desired effect. E.g. `http://www.google.com/search?q=this+will+work+great`. – Uwe Keim May 16 '11 at 08:27

3 Answers3

2

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.

TheVillageIdiot
  • 40,053
  • 20
  • 133
  • 188
0

You could set a cookie - that way the next time the user returns you could even return them to the same page (if you wanted to).

You may find this article helpful when deciding if this is a good option for you.

If you need to set the cookie on the client-side, then this article should help you out.

Nathan
  • 6,095
  • 2
  • 35
  • 61
  • Thanks for the prompt reply. But how can I set a cookie in the code. Is there any way I can add some code for the click event of the "Open in new tab" – Noel May 16 '11 at 06:42
  • Just added a link to help you out :) – Nathan May 16 '11 at 06:42
  • Once again thanks Nathan, but where exactly can I add the cookie details. It is the browser default context menu, and when I click "Open Link in New Tab", I dont know how to add some code of mine. – Noel May 16 '11 at 06:55
0

As @TheVillageIdiot said, url rewriting is a better approach. But you can use cross-page posting ability as well. Check it out:

Markup

<asp:HiddenField ID="HiddenField1" runat="server" ClientIDMode="Static" />

<asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
        <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/Second.aspx" Text='<%# Bind("Text") %>' OnClientClick='<%# "LinkButton1_Click(\"" + Eval("Value") + "\")" %>' />
    </ItemTemplate>
</asp:Repeater>

<script type="text/javascript">
    function LinkButton1_Click(v) {
        document.getElementById('HiddenField1').value = v;
    }
</script>

As you can see in the preceding code snippet, you have to add a hidden field to store the selected item by a simple javascript. Also I defined a property, called SelectedValue to get the value of the hidden field on the otherside.

Code Behind

protected void Page_Load(object sender, EventArgs e)
{
    Repeater1.DataSource = new[] {
        new { Text = "Item 1", Value = "Item 1" },
        new { Text = "Item 2", Value = "Item 2" },
        new { Text = "Item 3", Value = "Item 3" }
    };
    Repeater1.DataBind();
}

public string SelectedValue
{
    get { return HiddenField1.Value; }
}

Second Page

Add following directive to the destination page.

<%@ PreviousPageType VirtualPath="~/Default.aspx" %>

Finally, you have access to the previous page via PreviousPage property of Page class.

string value = ((_Default)this.PreviousPage).SelectedValue;
m3kh
  • 7,881
  • 2
  • 31
  • 37
  • I tried it. But there is one problem, the previous page is the same as the first page. So, it gave me a "circular reference error". My scenario is as follows. I've a grid with some rows. If i click on it, some widget has to load which will show the details of the selected row/selected panel item(whichever). Now, if I want this feature to come up in a new window, wot should I do so that the new page knows that I've already selected a row and the particular widget should be loaded as well – Noel May 16 '11 at 09:21
  • Pardon me @Noel, I didn't pay enough attention to your question. – m3kh May 16 '11 at 09:48