Reputation: 53
i want to pres on button in aspx page and then in the code behind (cs), redirect the current page to different link and open new tab with new link.
i tried to do:
Response.Write("window.open('"+newPath+"','_blank')");
Response.Redirect("~/book_details.aspx);
but every time i redirect only to ~/book_details.aspx (the second redirect) and the new tap with newPath does not open.
anybody have an idea how to implement it correctly?
thanks.
Upvotes: 0
Views: 2299
Reputation: 24147
It is better never to use Response.Write
and Response.Redirect
together. Response.Redirect
works best when no other output was written, and if it works (this may be browser dependent) then the output from Response.Write
may have little or no effect because the browser loads the new page immediately after.
Best is to do both actions in javascript. And you also need a <script>
tag for that.
Like this:
var redirectUrl = VirtualPathUtility.ToAbsolute("~/book_details.aspx");
var js = "window.open('" + newPath + "','_blank');"
+ "location.replace('" + redirectUrl + "');";
Response.Write("<script type='text/javascript'>" + js + "</script>");
Upvotes: 0
Reputation: 3228
Greetings it should be like below, when you are calling javascript
method within Response.Write
you need to add <script></script>
, also call your address within the Response.Write
Response.Write("<script>window.open('~/book_details.aspx','_blank'</script>");
Upvotes: 1