ASP.NET ボタンクリックでダイアログ画面を表示
📋 目次(クリックで展開)
ASP.NET 開発で、ボタンクリック時にダイアログ画面(ダイアログウィンドウ)を表示する例です。
.NET Framework 側で RegisterClientScriptBlock メソッドを呼び出してスクリプトを登録します。RegisterClientScriptBlock メソッドの第1引数、第2引数の情報の組み合わせでスクリプトを一意に識別しています。重複する組み合わせのスクリプトは登録できないようです。
以下の例では、ボタンクリックのタイミングで、Dialog.aspx というダイアログ画面を表示しています。
protected void Button1_Click(objectsender, EventArgs e){ ClientScript.RegisterClientScriptBlock( // クライアントスクリプトのタイプ this.GetType(), // クライアントスクリプトのキー "modal1", // スクリプト "<script language='javascript'>window.showModalDialog('Dialog.aspx');</script>" );}参考情報
- ClientScriptManager.RegisterClientScriptBlock メソッド (Type, String, String)
- window.showModalDialog
- showModalDialog method
💬 コメント