简体   繁体   中英

Open URL in new tab instead of window using c# code behind

  • I have one PDF on my page. But I want it to be opened only when a user is logged in.
  • For that I use a popup with login on the PDF link.
  • When he/she tries to login using this popup, the code behind it will come in to the picture.
  • And from there I have to decide whether or not the user can open the URL.
  • If he/she is an authentic user, the page will get refreshed with the user login, and the PDF link will get opened in a new tab instead of a new window.

if you are using Hyperlink then use Target Attribute

Behavior for Target Attribute is depend on Browsers

 target="_blank"

older browser --> In New Window cause No tabbing Support.

Newer browser---> new Tab.

and if You Want you use Button then markup your button definition like this,

<asp:Button ........OnClientClick="NameofForm.target ='_blank';"/>

in code behind use redirection

When user is authenticated, add a session variable to confirm authentication, use that session variable to check whether the user is authenticated or not and if authenticated, write a javascript code as:

window.open("http://www.yahoo.com");

So, after your page is refreshed post authentication, the window will open.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM