Opening A Url In A New Tab
I have an url like Response.Redirect('~/webpages/frmCrystalReportViewer.aspx?VoucherNo=' + txtVoucherNo.Text + '&VoucherDate=' + txtVoucherDate.Text + ' &strUserCode=' + s
Solution 1:
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)));
Solution 2:
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:ButtonID="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
<scripttype = "text/javascript">functionSetTarget() {
document.forms[0].target = "_blank";
}
</script>
calling the btnPrint_Click method OnClick event Control as described below
protectedvoidbtnPrint_Click(object sender, EventArgs e)
{
Response.Redirect("ReportViewer1.aspx");
}
Solution 3:
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";
Post a Comment for "Opening A Url In A New Tab"