2011-11-28 77 views
0

我試圖在單獨的選項卡/窗口中打開.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); 
} 
+1

您是否在頁面中放置了斷點?它會突破兩次嗎?這可能是一個雙重回寄麻煩? –

回答

2

好了,所以兩個問題 - 我想埃馬努埃萊·格列柯是正確的,它是在你的頁面週期被稱爲兩次。第二個問題是你每次都給它一個唯一的代碼。你應該放入相同的代碼(不是Guid.NewGuid())來確保腳本只添加一次。

E.g.

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

謝謝Emanuele Greco和rangitatanz。 Rangitatanz代碼爲我工作。再次感謝。如果你知道請幫忙,我還有一個問題。即時通訊在我的報告列表中使用自定義分頁,分頁不適合我,我可以爲您複製代碼。 – SunVigna

+0

最好是創建另一個問題 - 如果你喜歡,可以在這裏鏈接到它。 –

相關問題