In bleow code Page is opening in a new window. My requirement is to open it in a new tab.
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "popup",
"window.open('" + strFilePath + "','_blank')", true);
You can't open a new tab because that's up to the browser to decide. The user can configure his browser to open a new window on a separate tab. In the latter case, your code will work.
If you want the user to have a windows opened in a new tab, you can only display a link and have the user, right click it, etc.
Note, that clicking a link can still cause a postback on the current page.
You'll just use a redirection on your postback.
http://msdn.microsoft.com/en-us/library/ms153108.aspx
Never waste your effort controlling client environment, I have done it many times, may be disabling right click or opening in new window, and finally had to live up with client settings for my code or hack to work the way I expected it to.
In the mean time have a look at :-
Open a URL in a new tab (and not a new window) using JavaScript
Related
I'm trying to close the browser tab when user clicks on logout button or session expires but i am not able to close the tab
I have tried using the below solution but its not working.
ScriptManager.RegisterStartupScript(this, this.GetType(), "Close_Window", "window.close();", true);
When using the above code I'm getting console warning in the browser.
"Scripts may close only the windows that were opened by it."
Any help will be appreciated.
I would recommend that the logout action and expiring session will redirect you to a different page of your preference (e.g. Home page, Login Page, etc). Which you will normally encounter from other websites like social media sites.
Using window.close for certain browsers are considered risky just like how you received the warning message, because the window/tab was not opened (initiated) by the script themselves.
There are probably some workarounds that you can find, but that will still depend per browser, and the hack might differ among them. So I would not suggest this. But still you can find some details about this here in a SO question.
In my .net project, I want to create a button on a web page and when clicking on it, a new window will open. I added a web form to the same branch with the current webpage (named: webname).
In current webpage I add:
//Open new form:
Response.Redirect("~/webname.aspx");
But when I run, it open a link on new window, but cannot find this new webpage.
Error:
The resource cannot be found.
I really don't know how to point to the right place?
Try using the following
Response.Redirect("webname.aspx");
since, the web form located in the same branch as you said.
another option is to use HTML as follow
My Page
As you can see the HTML attribute target="_blank" tells browser to open new window for you.
Good luck.
How to avoid to open same window of existing website(window) in new tab
for eg.. if i have a page www.mysite.com/page1.aspx if i copy this
URL and paste in new tab of the browser than a popup or message
should be appear(alert-- you have already open this website)
Note: if we reload or refresh the previous page than alter should not be appear .means only one page can be open at a time
It should be done in scripting only, i need your valuable advice
thanks in advance
Create a cookie, set its value to true on page load and false on log off.
check if a cookie is true and same page loaded show your message.
I've got a webbrowser in a c# form and when the user click on a link the page opens in the ie10 browser.
All I want is to intercept this event and open the new page in another webbrowser (extendendwebbrowser really).
The fact is that i don't want to know what the user click in the page, but i'd like to intercept all the requests "open new page" from my webbrowser and redirect them to my extendedwebbrowserform and create a new tab with that link.
Thanks for help.
There are at least 2 ways to do that:
Extend the WebBrowser control to intercept the NewWindow2 event, then cancel original request and use that url to open it in a new window. Similar code can be found here or in code project Extended .NET 2.0 WebBrowser Control.
Implement INewWindowManager, and use EvaluateNewWindow to do the same.
I have this code implemented in my application, but whenever i click onto the link, it do help me open a new window. But the original page was "refresh", it kept go all the way back to the top. How can i resolve this problem?
code:
Response.Write("<script>window.open('" + url + "')</script>");
As I understand it, each time you click the link the page is being send to the server where the event is handled (with some C#). If you do that, the server will send the whole page back.
You probably want to control this on client side, with some Javascript.
That said, what you are problably looking for is the attribute target of the link:
something
That will tell the browser that you want to open another tab or windows when the user click the link, and then there request the page specified by url in that tab or window.
Sounds like you want Response.Redirect(myURL)
When you click on the link and handle it in the code behind, that means the link is run at the server side, so it has to post back, which makes it look like it's "refreshing", but it's actually posting back.
You need to handle the opening of the new window on the client's side via Javascript.
If your're writing this to your page, this will redirect you to the url you want
Response.Write("<script>;location.href='" + url + "'</script>");