忍者ブログ

[PR]

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

モーダルポップアップ

showModalDialog() を使用する方法
<base target="_self" />
 
2 つめの問題は、モーダルウィンドウの Page_Load() が呼ばれない場合があるということです。モーダルとして開いた 1 度目は Page_Load() が呼ばれますが、開いているウィンドウを閉じて再度モーダルウィンドウを開くと Page_Load() が呼ばれません。この問題を回避するには、モーダルウィンドウに毎回異なる QueryString を渡してアドレスを変えるという方法がありますが、根本的な解決には至っていません。

キャッシュクリア
Page_Loadで
Response.Cache.SetExpires(DateTime.Now.AddDays(-1))
 
window.open() を使用する方法
 
<body onblur="this.window.focus();">
 
ModalPopupExtender コントロールを使用する方法
 
アジャイルプログラマの日常
2007-11-07
ASP.NET でモーダルダイアログボックス
http://d.hatena.ne.jp/fyts/20071107/asp

 
★親画面
    Private Function PopupScript() As String
 
        Dim script As String = _
            <script>
                <!--ボタンのOnClientClickにセットするため、関数を呼び出すように記述-->
                ShowModal();
 
    <!--呼び出す関数-->
    function ShowModal() {
 
        var popup = '1';
        <!--ブラウザ判断-->
        var userAgent = window.navigator.userAgent.toLowerCase();
 
        <!--ポップアップ起動のオプション-->
        var opt
        if (userAgent.indexOf('chrome') != -1){
            if(popup=='1'){alert('chrome');}
 
            <!-- オプション chromeはpxが不要-->
            opt = 'dialogWidth:400;dialogHeight:200;';
        }else if(userAgent.indexOf('msie') != -1){
            if(popup=='1'){alert('msie');}
            <!-- オプション IEはpxが必要-->
            opt = 'dialogWidth:400px;dialogHeight:200px;';
        }
 
        <!--子に渡す値の準備-->
        var forename = document.getElementById('<%= Textbox2.ClientID %>');
        var surname = document.getElementById('<%= Textbox3.ClientID %>');
 
        <!-- 子に渡す値をセット-->
        var sharedObject = new Object();
        sharedObject.forename = forename.value;
        sharedObject.surname = surname.value;
 
        <!-- URLの作成 パラメータに子画面から値をセットする親画面のClientIDを渡す-->
        var URL
        URL = '<%= popupPage %>';
        URL += '?id=<%= Textbox2.ClientID %>';
 
        if (window.showModalDialog) {
 
            if(popup=='1'){alert('window.showModalDialog');}
 
            <!--モーダルダイアログ起動 第二引数に子に渡すオブジェクト-->
            var retValue = showModalDialog(URL, sharedObject, 'dialogWidth:400px; dialogHeight:400px; dialogLeft:300px;');
            if (retValue) {
                <!-- 子の値を受け取る -->
                UpdateFields(retValue.forename, retValue.surname);
            }else{
                <!-- chromeはこっち(値の受け取りは、子画面の中で親画面にアクセスして渡してある) -->
            }
        }
    }
 
    <!--子からの値をセットする関数-->
    function UpdateFields(newFore, newSur) {
        var forename = document.getElementById('<%= Textbox2.ClientID %>');
        var surname = document.getElementById('<%= Textbox3.ClientID %>');
        forename.value = newFore;
        surname.value = newSur;
    }
            </script>
 
        Return script
    End Function


★子画面
    Private Function PopupScript() As String
 
        Dim script As String = _
        <script>
            var popup = '1';
 
            if (window.showModalDialog) {
                if(popup=='1'){alert('returnValue');}
 
                <!-- 戻り値設定 -->
                if(window.opener){
                    if(popup=='1'){alert('window.opener');}
                    <!--chromeはモーダルダイアログじゃないので、こっち-->
            <!--URLに付けたパラメータのIDに対して、値をセット-->
                    window.opener.document.getElementById('<%= Request.QueryString("id") %>').value='<%= TextBox3.Text %>';
 
                }else{
                    <!--コード自体に意味はない。使い方のメモ-->
            <!--chromeはダイアログじゃないので、これ使えない。エラーになる-->
 
            <!--親画面からの値の受け取り-->
                    var arg = window.dialogArguments;
                    <!--親画面の値を使用-->
                    sharedObject.surname = arg.surname;
                }
 
                <!-- 戻り値設定 -->
                window.returnValue = sharedObject;
 
            }
 
            <!--ポップアップを閉じる-->
            window.close();
 
            </script>
 
        Return script
    End Function
 

PR

コメント

お名前
タイトル
文字色
メールアドレス
URL
コメント
パスワード Vodafone絵文字 i-mode絵文字 Ezweb絵文字

カレンダー

04 2024/05 06
S M T W T F S
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

カテゴリー

フリーエリア

最新コメント

プロフィール

HN:
No Name Ninja
性別:
非公開

バーコード

ブログ内検索

P R