1

特定の時点で、コード ビハインドに html を使用して動的に生成された文字列があります。
そのhtmlをソースとして持つポップアップを開きたいです。

私は次のことを試しました:私は自分のサイト (Javascript)
でこのメソッドを作成しました:.aspx

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

そして、コードビハインドで私はこれを持っています:

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

しかし、これを実行しようとすると、エラーが発生します。
ここで私が間違っていることは誰にもわかりますか?
または、誰かがこれを行うためのより良い方法を知っていますか?

4

1 に答える 1

1

編集

ボタンをクリックすると、このようになります

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 にクライアント スクリプトを登録します。

于 2013-01-11T09:56:57.547 に答える