Click here to Skip to main content
15,886,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually i am using below code to open new tab

OnClientClick="var originalTarget = document.forms[0].target; document.forms[0].target = '_blank'; setTimeout(function () { document.forms[0].target = originalTarget; }, 3000);"


the above code is using while clicking on the link button in that linkbutton i am redirecting to one file like pdf,xml

here my problem is if the file is there means it is opening correctly only but if the file is not there means it is opening same page from where i am clicking so i desided to do from code behind

is there any possibility to do like that
Posted
Comments
VC.J 17-Oct-14 6:19am    
from code behind you want to open a new page in new tab that what you want ?
ntitish 17-Oct-14 6:37am    
Yes. i want to open a new tab in the same browser where i am working
ntitish 17-Oct-14 6:37am    
not a new window
[no name] 17-Oct-14 6:42am    
If the file is there you show the file in a new tab, but if it is not there what is the logic for this you have?
ntitish 17-Oct-14 6:45am    
Nothing . for now i am not opening the new tab.

try this
you can do this like by adding attribute in anchor here I have anchor that you can use link button
var url = "abc.aspx";
anchor.Attributes.Add("target", "_blank");
anchor.Attributes.Add("href", "" + url + "");
 
Share this answer
 
Comments
ntitish 17-Oct-14 6:44am    
finaly what should we call. i mean
string url="pimage\log.pdf"
responce .redirect(url);

like the above code i have to call
VC.J 17-Oct-14 7:06am    
http://forums.asp.net/t/1564003.aspx?How+to+open+link+to+pdf+file+in+new+tab+using+html
is what you are looking for ?
and you want to open from c#
ntitish 17-Oct-14 7:14am    
sorry for not explaining my issue clearly. Actually from database i am binding documents to gridview with different types of documents like (.pdf,.xml,.txt,.doc... etc)
now i want to open the files in new tab after clicking the document view button. here i ac heaved opening in new window. but i want to open in new tab from where i am seeing the documents grid. the path will be dynamically given in code behind.
ntitish 18-Oct-14 3:39am    
Thanks i solved by using your concept in different manner.

while binding to the grid itself i added these atributes if the path is not found i am not binding these attributes
VC.J 18-Oct-14 5:32am    
thats great
Check here[^]
and also
How to code to open new tab in asp.net,c#[^]
Please check here if this helps you.
Please if not post back your queries in comments.
Thanks
:)
 
Share this answer
 
v2
Comments
ntitish 17-Oct-14 7:02am    
Actually i am asking for new tab in same browser not a new window. and i am passing file path dynamically not static like page.aspx
[no name] 17-Oct-14 7:39am    
Use this and check
I feel this will do your job.:)
ntitish 17-Oct-14 7:57am    
in the above given link opening new window but i am searching the result for new tab in the same window . it is not working
ntitish 17-Oct-14 7:59am    
In that link there are 5 solutions. which solution are you saying
[no name] 17-Oct-14 8:33am    
ClientScript.RegisterStartupScript(this.Page.GetType(), "",
"window.open('somepage.aspx','Graph','height=400,width=500');", true);
The code project solution. Window.Open() will let you open in new tab itself. :)

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