2011-10-29 31 views
0

這可能是一個簡單的,但我還沒有找到任何簡單的解決方案。從代碼背後的文件Html彈出窗口

單擊按鈕在asp.net網頁按鈕上單擊事件html是從xml和xsl生成的。這個html被存儲爲字符串變量。例如,讓我們說

dim htmlString as string = "<div>This is my popup</div>" 

從上面的html字符串我怎樣才能動態地在vb.net中創建html彈出窗口。我可以使用JavaScript創建前端彈出窗口,但還沒有找到任何解決辦法,通過隱藏文件的代碼在vb.net創建它

編輯:

這並不在IE瀏覽器,只適用於Firefox:

Dim popupScript As String = _ 
    "<script language='javascript'> myPopup() </script>" 
Dim mystring = "<html><body><div style=""color:black"">Name: Jame's</div></body></html>" 
Page.ClientScript.RegisterStartupScript(Me.GetType(), "PopupScript", String.Format(popupScript)) 
+1

我認爲這是ASP.NET,不是嗎?如何:'ClientScript.RegisterStartupScript(Me.GetType(),「newWindow」,String.Format(「」,url))' –

+0

謝謝蒂姆,這是我需要,我在發佈問題後發現了這一點。只是想知道是否有任何不使用JavaScript的不同方式。 – Jemsworld

回答

2

只能創建一個彈出窗口使用JavaScript,所以你需要從代碼隱藏註冊該腳本:

ClientScript.RegisterStartupScript(Me.GetType(), "newWindow", String.Format("<script>window.open('{0}');</script>", url)) 

也許我誤解你的要求。您不僅希望從代碼隱藏中打開客戶端彈出式窗口(window.open),還要在沒有url的情況下即時創建該窗口?

也許這會有所幫助(未經測試):

Dim popupHtml = "<html><body><div style=""color:black"">Name: Jame's</div></body></html>" 
Dim openPopupScript = "NewPopup=window.open("", 'newWindow', 'height=250, width=250');" & _ 
         "NewPopup.document.open();" & _ 
         String.Format("NewPopup.document.write('{0}');", popupHtml) & _ 
         "NewPopup.document.close();" 
ClientScript.RegisterStartupScript(Me.GetType(), _ 
         "newWindow", _ 
         openPopupScript) 
+0

如何將vb.net strig包含html作爲參數傳遞給javascript函數? Jemsworld

+0

上代碼debhind文件昏暗popupScript作爲字符串= 「」 了mystring = 「

Name: Jame's
」 Page.ClientScript.RegisterStartupScript(Me.GetType( ),「PopupScript」,String.Format(popupScript)) 母鹿不工作在IE瀏覽器只能在Firefox上工作 – Jemsworld

+0

抱歉,但我無法很好地格式化評論 – Jemsworld