how to get link to open new tab in browser?

1.7k Views Asked by At

I have a save button that saves all the information the user enters from a form into the database. Once all that is done, I want a new tab to automatically open.

So the code checks if the save is successful then I want the new tab to open.

if (NewQuoteID != -1)
{
     Response.Redirect("Printouts/DSVQuotation.aspx?QuoteID=" + NewQuoteID.ToString(), false);
}

Code for the save button:

<asp:LinkButton runat="server" ID="btnSave" CssClass="btnSaveLarge loading" OnClientClick="return CheckNoOfDetails()" ToolTip="Save Quote" OnClick="btnSave_Click" Text="Save"  /> 

This code opens the link on the same tab. How do I get the link to open on a new tab in the browser? I see a lot of examples are setting the OnClientClick to something like this: OnClientClick="aspnetForm.target ='_blank';" But I am already calling a method in the OnClientClick

3

There are 3 best solutions below

1
blogprogramisty.net On

Try this:

 OnClientClick="window.open('New.aspx')"

But question is duplicated, here is the full answer

how to open a page in new tab on button click in asp.net?

0
Herrbifi On

Try something like this

 string script = "<script>window.open('Printouts/DSVQuotation.aspx?QuoteID=" + NewQuoteID.ToString() + "','_blank');</script>"

response.write(script);

1
levent On

if you want open tab after server side save operation is success..

client side :

 <script type="text/javascript">
    var openNewTab = function (url) {
        window.open(url);
    }
</script>

server side

        if (NewQuoteID != -1)
        {
            var url = "Printouts/DSVQuotation.aspx?QuoteID=" + NewQuoteID.ToString();
            ClientScript.RegisterStartupScript(this.GetType(), "openmypage", string.Format("openNewTab('{0}');", url), true);
        }