Javascript 为什么我的代码会打开两个窗口?

Javascript 为什么我的代码会打开两个窗口?,javascript,asp.net,Javascript,Asp.net,我正在尝试在单独的选项卡/窗口中打开.pdf文件。它正在工作,但是它打开了两个窗口来显示.pdf LinkButton btn = (LinkButton)(sender); string value = btn.CommandArgument; imfImageFile = LocalStaticData.UniImageResult; string path = imfImageFile.WindowsPath; if (path != "") { Session["OpenPDF

我正在尝试在单独的选项卡/窗口中打开.pdf文件。它正在工作,但是它打开了两个窗口来显示.pdf

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);
}

好的,有两个问题-我认为Emanuele Greco是对的,它在您的页面周期中被调用了两次。第二个问题是每次都给它一个唯一的代码。您应该输入相同的代码(而不是Guid.NewGuid()),以确保只添加一次脚本

例如


你在页面上放了断点吗?它断了两次吗?这可能是一个双重回邮麻烦吗?谢谢Emanuele Greco和Rangitanz。Rangitanz代码对我有用。再次感谢。我还有一个问题,如果你知道的话,请帮忙。我在我的报告列表中使用自定义分页,分页不适用于我,我可以为您复制代码。如果您愿意,最好创建另一个问题-在此处链接到它。
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(),
    "InvoiceReportPDFOpenScript", "openPdf(\"../InvoiceReport.aspx\" );", true);
}