I do not necessarily have to use response.redirect, but that is what I had. I would like to open the selected link in a new window. How do I do that?
context
You can't is the short answer. The browser is the only thing that can open up a new window.
What you can do is send a chunk of html down the response that has a link with your url as an href, target="_blank" and a chunk of javascript onload of the form that fakes a click. If this doesn't work then use a window.open(url);
response.write("<script>");
response.write("window.open('page.html','_blank')");
response.write("</script>");
How about a hyperlink that you program dymanically? Imagine this. asp hyperlink that when you click opens a new window, possibly with no scroll bars, no address bar, anything you want. Here is an example:
hyperlink1.Attributes.Add("onclick", "window.open(http://www.mylink.com?sessionvar1=" + someValue + "',null,'height=251px, width=600px,status=no, resizable=no, scrollbars=no, toolbar=no,location=no,menubar=no ');");
This is just an alternative to a standard button that would otherwise call a click handler. Keep in mind, you can add the whole thing from the front as an attribute.
You cannot do that with Response.Redirect()
Well you could do this using a simple Javascript inside Response.Write
Response.Write("<script>window.open('page.html','_blank')</script>");
This works for me
On aspx code:
<a id="myLink" target="_blank" onclick="window.open('ExamplePage.aspx, '_blank');">Link To A Page And Open Other Tab</a>
I added to @DaveWalker response:
Response.Write("<script>")
Response.Write("window.open('NewPage.aspx','_blank','resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,location=no')")
Response.Write("</script>")
This will create a popup instead of opening a new tab.
I've seen many anwers and no one really works for me. So I tried the following code and it solved my problem:
First I changed mt button by a linkbutton with the same aspect as a button.
<asp:LinkButton ID="btPrint" runat="server" class="btn btn-primary"><span class="glyphicon glyphicon-print"></span> Print</asp:LinkButton>
After this I add the following in my code behind.
btPrint.Attributes.Add("href", String.Format("printPage.aspx?&id={0}", txtId.Text));
btPrint.Attributes.Add("target", "_blank");