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...
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.
The answer given by anand360 worked for me. Thanks!!
I made a slight change in JavaScript as follows to access only the desired element.
document.getElementById["element_id"].target = "_blank";
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
I have an ASP.Net Button
<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
<script type = "text/javascript">
function SetTarget() {
document.forms[0].target = "_blank";
}
</script>
calling the btnPrint_Click method OnClick event Control as described below
protected void btnPrint_Click(object sender, EventArgs e)
{
Response.Redirect("ReportViewer1.aspx");
}
You are using URL with ~ and it won't recognize by javascript. You should process url with ~ by using ResolveUrl method which
converts a URL into one that is usable on the requesting client(c)msdn
In your case:
Response.Write(String.Format("window.open('{0}','_blank')", ResolveUrl(pageurl)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With