Search code examples
c#asp.nethttp-redirecthyperlinklinkbutton

Opening new tab using a link with querystring variable?


First of all, I am entirely new to web development, so I apologize in advance if this question is overly simple (although I did do the prerequisite googling before I posted).

The problem I am having is that I would like to open a new tab via a link button or link on my page. I need to append a query string variable from the page onto the end of the reference, because it is passing a parameter to a report.

I've successfully passed the parameter and opened the report in the same tab using this code:

protected void lbSummary_OnClick(object sender, CommandEventArgs e)
    {
        Response.Redirect("http://myreportserverURL&rs:Command=Render&Year="+YearID);
    }

And I've successfully opened the report in a new tab without passing the parameter with this code:

<a href="http://myreportserverURL" target="_blank" class="menu">Report Name</a>

I would prefer to do both. One important note is that opening a new window, instead of a new tab, is not what I need. I do understand that this is somewhat dependant on browser use, but for this project I can assume that users will be on IE8.

Is this possible? Any suggestions would be greatly appreciated.


Solution

  • You can use asp.net HyperLink control where you can set it's NavigateUrl in code-behind to whatever link you want including your querystring in there.

    You can set it's Target Property as per you need.