简体   繁体   English

在ASP.NET网页中打开“新建标签”

[英]Open New Tab in ASP.NET web page

After clicking on ASP.NET button, it redirects to correct website but on the same tab, not in a new tab, which I need to do. 单击ASP.NET按钮后,它将重定向到正确的网站,但位于同一选项卡上,而不是在新选项卡中,这是我需要做的。 After clicking the button twice, it redirects the website in a new tab. 两次单击按钮后,它将在新选项卡中重定向网站。 I don't know what's wrong with my code! 我不知道我的代码有什么问题!

The ASP.NET button control looks like this: ASP.NET按钮控件如下所示:

<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="../Images/neu.png" OnClick="New_btn_click" />

And the code that is run is this: 运行的代码是这样的:

protected void New_btn_click(object sender, EventArgs e)
{
    ImageButton1.Attributes.Add("onclick", "window.open('new_model_epk.aspx');return false;");   
}

What you're describing is exactly what I would expect. 您所描述的正是我所期望的。 The JavaScript isn't run until the second time because it hasn't been added until after you click the button the first time. 该JavaScript直到第二次才运行,因为直到您第一次单击该按钮后才添加该JavaScript。 Don't even use C#; 甚至不要使用C#。 just use this: 只需使用此:

<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="../Images/neu.png" OnClientClick="window.open('new_model_epk.aspx');return false;" />

Any JavaScript in the OnClientClick attribute will run right away when you click the element, so C# code is unnecessary. 单击该元素时, OnClientClick属性中的任何JavaScript都将立即运行,因此不需要C#代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在新页面或选项卡中打开ASP.NET GridView项-如何? - Open ASP.NET GridView item in new page or tab - how to? 单击按钮后,页面应在新选项卡-asp.net中打开 - On Button click, page should open in new tab -asp.net 在ASP.NET的“新建”选项卡中打开链接 - Open Link in New Tab in ASP.NET asp.net:如何使用c#在新窗口(不是标签页或当前页面)中打开新的asp.net页 - asp.net: How to open a new asp.net page in new window (not tab or current page) using c# 如何打开从Iframe重定向的页面,以在ASP.NET的父窗口中作为新标签打开? - How to open the redirected page from Iframe to open as a new tab in the parent window in ASP.NET? 在新窗口中打开asp.net页面 - open asp.net page in new window 运行asp.net核心api项目时如何在vscode中设置不打开新的web浏览器选项卡 - How to set not to open new web browser tab in vscode when running asp.net core api project 如何在没有刷新ASP.NET Web窗体中的当前页面的情况下打开另一个选项卡? - How to open another tab on click without refresh current page in ASP.NET Web Forms? 使用 ASP.NET 按钮、C# 和页面背后的代码在新选项卡中打开窗口 - Open Window in new tab using an ASP.NET Button, C#, and the code behind the page 如何使用响应在新选项卡中打开页面。 重定向至 asp.net - How to open page in new tab using the response. redirect at asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM