I’m trying to open a .pdf file in separate tab/window. It’s working, but it opens two windows to show the .pdf.The code I used is as follows.
LinkButton btn = (LinkButton)(sender);
string value = btn.CommandArgument;
imfImageFile = LocalStaticData.UniImageResult;
string path = imfImageFile.WindowsPath;
if (path != "")
{
Session["OpenPDFImage"] = path;
ScriptManager.RegisterStartupScript(Parent.Page, GetType(),
Guid.NewGuid().ToString(), "openPdf(\"../InvoiceReport.aspx\" );", true);
}
JavaScript:
function openPdf(href) {
window.open(href);
}
Ok so two issues – I think Emanuele Greco is right that it is being called twice in your page cycle. The second issue is that you are giving it a unique code every time. You should be putting in the same code (not Guid.NewGuid()) to make sure the script only gets added once.
E.g.