How can I programatically open a new page in a new tab from my codebind file in ASP.NET?

情到浓时终转凉″ 提交于 2019-12-24 03:25:49

问题


How can I programatically open a page in a new tab from my code behind file in ASP.NET after clicking on a button in my first page? Hopefully, from the new page I could also get to the Session[] array.


回答1:


"Code behind" runs on the server, no browser instances there to open/use.
Javascript runs in the browser, on the client's computer, it can open a new tab.
If you want, you will have to write a piece in C# that will generate a JavaScript snippet with the window.open Command.




回答2:


Kelsey's code is correct, but is now depricated, the suggested way to do it now is to use the ScriptManager's methods like this.

ClientScript.RegisterStartupScript(GetType(), "SomeNameForThisScript",
           "window.open('YourPage.aspx');", true);



回答3:


Just register a window.open command in the start client script.

In your C# client side code (event):

RegisterStartupScript("SomeNameForThisScript", "window.open('YourPage.aspx');");

When you page is served up, the startup script will fire and open a new window. You can customize how the window.open works via attributes.




回答4:


How about Response.Redirect("~/formname.aspx?Parameters=" + yourparamater); ?



来源:https://stackoverflow.com/questions/1215505/how-can-i-programatically-open-a-new-page-in-a-new-tab-from-my-codebind-file-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!