I am using below code for open page in popup window.
ScriptManager.RegisterStartupScript(Page, GetType(Page), "OpenWindow", "window.open('URL');", True)
But i want to page open in New Tab. Can any one help me in that.
I am using below code for open page in popup window.
ScriptManager.RegisterStartupScript(Page, GetType(Page), "OpenWindow", "window.open('URL');", True)
But i want to page open in New Tab. Can any one help me in that.
You will need to make the JavaScript call a user initiated event.
Please see this question and answer for further details (specifically, see point 3 in the answer).
Working example.
<input type="button" value="Click Me" onclick="openWindow()" />
function openWindow() {
window.open('http://www.google.com/', '_blank');
}
You can use ClientScript.RegisterStartupScript
I tried In Google Chrome its working but Not In Firefox In aspx Code
<asp:Button Text="" OnClick="Button1_Click" ID="Button1" runat="server" />
In C#
protected void Button1_Click(object sender, EventArgs e)
{
string queryString = "test.aspx" ;
string newWin = "window.open('" + queryString + "','_blank');";
ClientScript.RegisterStartupScript(this.GetType(), "pop", newWin, true);
}
In VB
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim queryString As String = "test.aspx"
Dim newWin As String = "window.open('" + queryString + "','_blank');";
ClientScript.RegisterStartupScript(Me.GetType(), "pop", newWin, True)
End Sub
Try replacing this with your script
window.open('URL', '_blank')
and I think it's browser setting that decide whether to open new window or tab. Have a look in to that as well.
found this; If nothing works try this link
You can try this..working for me in all browsers...
ScriptManager.RegisterStartupScript(this, this.GetType(), "onclick", "javascript:window.open(
'URL','_blank','height=600px,width=600px,scrollbars=1');", true);
Please Mark as answer if it satisfies you..
check this example for you,
ScriptManager.RegisterClientScriptBlock(btnsave, this.GetType(), "Open",
"window.open('GenerateDCNoPrint.aspx?indentno=" + ddlindentno.SelectedItem.Text +
"&orderno=" + ddlindentno.SelectedValue + "&lorryno=" + txtlorryno.Text.Trim() +
"&depaturetime=" + txtdeparture.Text.Trim() + "&date=" + txtdate.Text + "',
'_blank','dependent,resizable=yes,scrollbars=yes,top=0,height=600');", true);
try this
Page.ClientScript.RegisterStartupScript(this.GetType(), "OpenWindow", "window.open('WebForm2.aspx', '_blank');", true);
or
string url = "WebForm2.aspx";
string s = "window.open('" + url + "', 'popup_window', 'width=300,height=100,left=100,top=100,resizable=yes');";
ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
I have searched and tried many solutions but finally, this works for me.
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "newWindow", "window.open('google.com','_blank','status=1,toolbar=0,menubar=0,location=1,scrollbars=1,resizable=1,width=700,height=400');", true);