[英]Open Popup with dynamicly generated Html from CodeBehind
在某個時候,我的代碼中有一個帶有html的動態生成的字符串。
我想打開一個具有該html作為其源的彈出窗口。
我嘗試了以下方法:
我在.aspx
網站(Javascript)上創建了此方法:
function OpenWindowWithHtml(html, title) {
var myWindow = window.open('', title);
myWindow.document.write(html);
myWindow.focus();
}
在后面的代碼中,我有這個:
Response.Write("OpenPopupWithHtml(\"" + html + "\", \"" + title + "\");");
但是,當我嘗試執行此操作時,出現錯誤。
有人看到我在這里做錯了嗎?
還是有人知道更好的方法?
編輯
在按鈕上單擊它應該像這樣
protected void btnAbct_Click(object sender, EventArgs e) {
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "OpenPopupWithHtml('" + html + "', '" + title + "');");
}
執行代碼即 您用JavaScript編寫的功能
ClientScript.RegisterStartupScript(this.GetType(),
"newWindow", "OpenPopupWithHtml('" + html + "', '" + title + "');");
您可以像這樣注冊客戶端腳本
if (!ClientScript.IsClientScriptBlockRegistered("exampleScript"))
ClientScript.RegisterStartupScript(this.GetType(), "exampleScript","
<script language = "'javascript'">
alert('you just registered the start up script')
</script>
");
從asp.net文件后面的代碼
要打開彈出窗口,只需在上面的代碼中替換此行
ClientScript.RegisterStartupScript(this.GetType(),
"newWindow", String.Format("<script>window.open('{0}');</script>",
"mypage.html"));
詳細檢查: 在ASP.NET中注冊客戶端腳本
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.