0

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

Emond
  • 50,210
  • 11
  • 84
  • 115
user123456789
  • 1,914
  • 7
  • 44
  • 100
  • You could try to set the form's target in the OnClientClick method – Emond Jan 27 '16 at 14:38
  • If you are using jQuery you may create an event listener for that button (with client ID) then you can easily do whatever you need on client side. Have you tried that ? – Cihan Uygun Jan 27 '16 at 14:40
  • Possible duplicate of [how to open a page in new tab on button click in asp.net?](http://stackoverflow.com/questions/10493901/how-to-open-a-page-in-new-tab-on-button-click-in-asp-net) – M. Schena Jan 27 '16 at 14:45

3 Answers3

3

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?

Community
  • 1
  • 1
blogprogramisty.net
  • 1,714
  • 1
  • 18
  • 22
0

Try something like this

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

response.write(script);

Herrbifi
  • 11
  • 5
0

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);
        }
levent
  • 3,464
  • 1
  • 12
  • 22