在新标签页中打开网址

时间:2022-12-09 20:16:21

I have an url like

我有一个网址

Response.Redirect("~/webpages/frmCrystalReportViewer.aspx?VoucherNo=" + txtVoucherNo.Text + "&VoucherDate=" + txtVoucherDate.Text + " &strUserCode=" + strUserCode.ToString() + "&strCompanyCode=" + strCompanyCode.ToString() + "&formName=frmPaymentVoucher");

I want to open this url in new tab of browser. I tried below code...

我想在浏览器的新选项卡中打开此URL。我尝试下面的代码......

string pageurl = "~/webpages/frmCrystalReportViewer.aspx?VoucherNo=" + txtVoucherNo.Text + "&VoucherDate=" + txtVoucherDate.Text + " &strUserCode=" + strUserCode.ToString() + "&strCompanyCode=" + strCompanyCode.ToString() + "&formName=frmPaymentVoucher";
Response.Write("<script>");
Response.Write("window.open('" + pageurl + "','_blank')");
Response.Write("</script>");

also i tried below

我也试过下面

string pageurl = "~/webpages/frmCrystalReportViewer.aspx?VoucherNo=" + txtVoucherNo.Text + "&VoucherDate=" + txtVoucherDate.Text + " &strUserCode=" + strUserCode.ToString() + "&strCompanyCode=" + strCompanyCode.ToString() + "&formName=frmPaymentVoucher";
 ScriptManager.RegisterStartupScript(Page, Page.GetType(), "popup", "window.open('" + pageurl + "','_blank')", true);

also i tried

我也试过了

<asp:Button ID="btnPrint" Text="Print" runat="server" OnClick="btnPrint_Click" OnClientClick="aspnetForm.target ='_blank';"/>

but all are not working. Please tell me any another solution. Thanks in advance.

但都没有用。请告诉我任何其他解决方案。提前致谢。

2 个解决方案

#1


10  

You are using URL with ~ and it won't recognize by javascript. You should process url with ~ by using ResolveUrl method which

您正在使用带有〜的URL,它将无法通过javascript识别。你应该用〜使用ResolveUrl方法处理url

converts a URL into one that is usable on the requesting client(c)msdn

将URL转换为可在请求客户端上使用的URL(c)msdn

In your case:

在你的情况下:

Response.Write(String.Format("window.open('{0}','_blank')", ResolveUrl(pageurl)));

#2


1  

With the help of JavaScript we can set the target property of form to _blank whenever we want to open the page in a new window. Try the following

在JavaScript的帮助下,只要我们想在新窗口中打开页面,我们就可以将表单的target属性设置为_blank。请尝试以下方法

I have an ASP.Net Button

我有一个ASP.Net按钮

 <asp:Button ID="btnPrint" runat="server" Text="PRINT BILL" Onclick="btnPrint_Click"  OnClientClick="SetTarget();" />

I am calling the SetTarget() JavaScript function OnClientClick event of the ASP.Net Button Control as described below

我正在调用ASP.Net Button Control的SetTarget()JavaScript函数OnClientClick事件,如下所述

<script type = "text/javascript">
 function SetTarget() {
     document.forms[0].target = "_blank";
 }
</script>

calling the btnPrint_Click method OnClick event Control as described below

调用btnPrint_Click方法OnClick事件控件如下所述

 protected void btnPrint_Click(object sender, EventArgs e)
    {
         Response.Redirect("ReportViewer1.aspx");
    }

#1


10  

You are using URL with ~ and it won't recognize by javascript. You should process url with ~ by using ResolveUrl method which

您正在使用带有〜的URL,它将无法通过javascript识别。你应该用〜使用ResolveUrl方法处理url

converts a URL into one that is usable on the requesting client(c)msdn

将URL转换为可在请求客户端上使用的URL(c)msdn

In your case:

在你的情况下:

Response.Write(String.Format("window.open('{0}','_blank')", ResolveUrl(pageurl)));

#2


1  

With the help of JavaScript we can set the target property of form to _blank whenever we want to open the page in a new window. Try the following

在JavaScript的帮助下,只要我们想在新窗口中打开页面,我们就可以将表单的target属性设置为_blank。请尝试以下方法

I have an ASP.Net Button

我有一个ASP.Net按钮

 <asp:Button ID="btnPrint" runat="server" Text="PRINT BILL" Onclick="btnPrint_Click"  OnClientClick="SetTarget();" />

I am calling the SetTarget() JavaScript function OnClientClick event of the ASP.Net Button Control as described below

我正在调用ASP.Net Button Control的SetTarget()JavaScript函数OnClientClick事件,如下所述

<script type = "text/javascript">
 function SetTarget() {
     document.forms[0].target = "_blank";
 }
</script>

calling the btnPrint_Click method OnClick event Control as described below

调用btnPrint_Click方法OnClick事件控件如下所述

 protected void btnPrint_Click(object sender, EventArgs e)
    {
         Response.Redirect("ReportViewer1.aspx");
    }