Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
I need to display the PDF file in next tab when i click on Image button in DataList.The file path will cum dynamically.


Here's My DataList code

<asp:DataList ID="dlist_all" runat="server" RepeatDirection="Horizontal" RepeatColumns="3" onitemcommand="dlist_all_ItemCommand">
<itemtemplate>
<asp:ImageButton ID="img_download" CausesValidation="false" runat="server" CommandArgument='<%# Eval("id") %>' CommandName="PDF" AlternateText="PDF" ImageUrl="~/Images/pdficon.jpg" width="75" height="70" />



Here is my Cs Code to open a PDF file in Next Tab... But its open in new window not in a Next Tab for all Browser specially for Google Chrome

string script = "<script type='text/javascript'>window.open('" + url + "')</script>";
this.ClientScript.RegisterStartupScript(this.GetType(), "script", script);


Please Send me the Code as Soon as Possible...
Posted
Updated 30-Sep-14 2:08am
v3

You can force that behavior!
There is no way to tell via HTML and/or JavaScript where to open the content of a link...
(to be more precise there is a target attribute on the <a> element but it can not be used to distinguish between new window and new tab...)
 
Share this answer
 
v2
javascript excuting from .cs page has no control over the users current browser instance... so it can not open file in a new tab 

Alternative would be binding a anchor tag dynamically with target='_blank'
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 30-Sep-14 9:03am    
That will not do - "_blank" only tells browser to open link in new instance, but do not decide if it is a new window or new tab...
PJ003 30-Sep-14 9:13am    
here is a sample code that worked for me before, a label placed in gridview and binded from .cs page... on clicking it opens file in new tab...



lblF1.Text = "<* href='\\File\\" + Convert.ToString(_dt.Rows[0]["varFile"]) + "' target=_blank>Open File ";



* == a
Kornfeld Eliyahu Peter 30-Sep-14 9:19am    
It is because the way your browser configured and not because of the "_blank" target!
For instance the very same link, with "_self", will open in the same window with right click, but in new tab with middle click in most browsers, but can be changed...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900