Redirect to new tab in ASP.NET

1.7k views Asked by At
 <asp:LinkButton ID="lnkBtnPrint" runat="server" OnClick="lnkBtnPrint_OnClick" Target="_blank">
                    </asp:LinkButton>

I have Button. I need to open new tab with content on click.

 protected void lnkBtnPrint_OnClick(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(hdnSubmissionID.Value))
        {
            SessionHelper.Set(SessionKey.SubmissionId, hdnSubmissionID.Value);
            Response.Redirect(PublisherConfigurationManager.Navigation + "Printable_Submission_Document.aspx");
        }
    }

I try to apply answer from this post Opening a URL in a new tab to my case, but just get text in top-left corner like 'window.open...'.

Add _blank to link - also doesn't help.

1

There are 1 answers

4
David L On BEST ANSWER

You are dynamically redirecting based on a triggered click. I think for this scenario, you could actually change it to set your HRef BEFORE the click, since you know your data on page load, provided that your sample code is complete.

public void Page_Load()
{
    if (!string.IsNullOrEmpty(hdnSubmissionID.Value))
    {
        SessionHelper.Set(SessionKey.SubmissionId, hdnSubmissionID.Value);
        lnkBtnPrint.HRef = PublisherConfigurationManager.Navigation + "Printable_Submission_Document.aspx");
    }
}

Keep your target set the way it is and remove the onclick event from your link button. It should now open your "dynamic" target in a new window.