简体   繁体   English

使用CodeBehind动态生成的HTML打开弹出窗口

[英]Open Popup with dynamicly generated Html from CodeBehind

At a certain point i have a dynamicly generated string with html in my code-behind. 在某个时候,我的代码中有一个带有html的动态生成的字符串。
I want to open a popup with has that html as its source. 我想打开一个具有该html作为其源的弹出窗口。

I have tried the following: 我尝试了以下方法:
I created this method on my .aspx site (Javascript): 我在.aspx网站(Javascript)上创建了此方法:

    function OpenWindowWithHtml(html, title) {
            var myWindow = window.open('', title);
            myWindow.document.write(html);
            myWindow.focus();
     }  

And in the code-behind i have this: 在后面的代码中,我有这个:

    Response.Write("OpenPopupWithHtml(\"" + html + "\", \"" + title + "\");");  

But when i try to execute this i get an error. 但是,当我尝试执行此操作时,出现错误。
Does anybody see, what i do wrong here? 有人看到我在这里做错了吗?
Or does somebody know a better way to do this? 还是有人知道更好的方法?

EDIT 编辑

on button click it shoudl be like this 在按钮上单击它应该像这样

protected void btnAbct_Click(object sender, EventArgs e) {
   ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "OpenPopupWithHtml('" + html + "', '" + title + "');");
}

To execute the code ie. 执行代码即 function you written in javascript 您用JavaScript编写的功能

 ClientScript.RegisterStartupScript(this.GetType(),
   "newWindow", "OpenPopupWithHtml('" + html + "', '" + title + "');");

you can register client script like this 您可以像这样注册客户端脚本

if (!ClientScript.IsClientScriptBlockRegistered("exampleScript"))
    ClientScript.RegisterStartupScript(this.GetType(), "exampleScript","
<script language = "'javascript'">
alert('you just registered the start up script')
</script>
");

from the code behind file of asp.net 从asp.net文件后面的代码

To Open pop-Up window , just replace this line in above code 要打开弹出窗口,只需在上面的代码中替换此行

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

Check this for detail : Register Client script in ASP.NET 详细检查: 在ASP.NET中注册客户端脚本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM