[英]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.