Click here to Skip to main content
14,488,717 members
Rate this:
Please Sign up or sign in to vote.
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.
[no name] 17-Oct-14 6:48am
   
you mean even if the file exists it is not opening in a new tab?
ntitish 17-Oct-14 6:52am
   
no not like that. i am trying for a functionality like if the file is there means i want to open file in a new tab in the same browser from where i am opening from code behind . if the file not exist in the path what i given i want to stop redirecting.
Rate this:
Please Sign up or sign in to vote.

Solution 1

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 + "");
   
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
Rate this:
Please Sign up or sign in to vote.

Solution 2

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
:)
   
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. :)
ntitish 17-Oct-14 9:01am
   
if i use the above code it will open in a new window with new tab . but i am asking for new tab in same window .
[no name] 17-Oct-14 9:03am
   
http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_open
Please see here what window.open is doing. :)
ntitish 18-Oct-14 2:56am
   
thanks for your answer if i calling that javascript function from .cs it is opening new window.
when i am using that java script in .aspx it is opening new tab. is there any problem with .cs
[no name] 18-Oct-14 4:32am
   
yes please check the .cs file please

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100