C# 在ASP.NET的“新建”选项卡中打开链接

C# 在ASP.NET的“新建”选项卡中打开链接,c#,asp.net,C#,Asp.net,我正在尝试使用按钮在ASP.NET的新选项卡中打开链接。我正在尝试以下操作,但不起作用: <asp:Button ID="ReportButton" runat="server" CssClass="button" Font-Size="XX-Large" ForeColor="White" Text="Report" OnClick="ReportButton_Click" OnClientClick="form1.target='_blank';" /> GoToPage的定

我正在尝试使用按钮在ASP.NET的新选项卡中打开链接。我正在尝试以下操作,但不起作用:

<asp:Button ID="ReportButton" runat="server" CssClass="button" Font-Size="XX-Large" ForeColor="White" Text="Report" OnClick="ReportButton_Click" OnClientClick="form1.target='_blank';" /> 
GoToPage的定义如下:

protected void SkidPackReportButton_Click(object sender, EventArgs e)
{
    GoToPage(LocationSkidPackReportPage);
}
bool GoToPage(string page)
{
    try
    {
        Response.Redirect(page);
        return true;
    }
    catch (Exception)
    {
        StatusLabel.Text = "There was an error finding the page.";
        return false;
    }
}
不做服务器端响应。重定向,只做客户端窗口。打开。例如

或者更好的办法是完全避免回发。您可以将clientClick分配给按钮,如下所示:

ReportButton.OnClientClick = String.Format("window.open({0});return false;", LocationSkidPackReportPage);
这样,新页面将在客户端打开,而无需返回到服务器。

不要执行服务器端响应。重定向,只需执行客户端窗口。打开。例如

或者更好的办法是完全避免回发。您可以将clientClick分配给按钮,如下所示:

ReportButton.OnClientClick = String.Format("window.open({0});return false;", LocationSkidPackReportPage);
这样,新页面将在客户端上打开,而无需返回服务器。

将LocationSkidPackReportPage设置为代码隐藏中的公共属性,然后将按钮替换为:

<a href="<%=LocationSkidPackReportPage%>" class="button" target="_blank">Report</a>
将LocationSkidPackReportPage设置为代码隐藏中的公共属性,然后将按钮替换为:

<a href="<%=LocationSkidPackReportPage%>" class="button" target="_blank">Report</a>
这是我的工作

  Page.ClientScript.RegisterStartupScript(
   this.GetType(), "OpenWindow", "window.open('../_Reportes/ReporteGeneral.aspx','_newtab');", true);
这是我的工作

  Page.ClientScript.RegisterStartupScript(
   this.GetType(), "OpenWindow", "window.open('../_Reportes/ReporteGeneral.aspx','_newtab');", true);

无法回发到服务器并打开新选项卡/窗口。浏览器的弹出窗口拦截器将阻止窗口。您试图实现什么?显示的错误是什么?您无法发回服务器并打开新选项卡/窗口。浏览器的弹出窗口拦截器将阻止窗口。你想实现什么?显示的错误是什么?为了让它工作,我应该把它放在哪里?如果你使用第一个版本-它只是取代了你原来的GoToPage函数。如果使用第二个版本,则必须将LocationSkidPackReportPage值更改放在何处?我应该将其放在何处才能使其正常工作?如果使用第一个版本,则它只会替换原始的GoToPage函数。如果你选择second,你必须把LocationSkidPackReportPage的值更改放在哪里,你应该解释你在答案中发布的任何代码;这样做的目的是帮助提问者,让他了解问题是如何解决的,而不是简单地与他/她一起解决问题;这样做的目的是帮助提问者,让他了解问题是如何解决的,而不是简单地带着解决方案。