表題の通りですが、modalウインドウ内のDropDownListをおいて
AutoPotBackをtrueにするとポストバックするので、modalが消えてしまうので、
別の方法を取りたいのですが、何か良い案はないでしょうか。
モーダルがスライドインのアニメーションを入れているので
ポストバックを受け取って、再度モーダルを表示するのは避けたいとおもっています。
気になる質問をクリップする
クリップした質問は、後からいつでもMYページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/29 15:10
退会済みユーザー
2016/09/30 02:16
回答2件
0
DropDownList をクリックすると、DropDownList の選択結果をサーバーに送信して、サーバー側で何らかの処置を行うのであろうと想像してサンプルを作ってみました。
<%@ Page Language="C#" %> <%@ Import Namespace="System.Web.Services" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> // 以下のページの Modal のデモのコードほとんどそのまま使用 // http://getbootstrap.com/javascript/ // jQuery.Ajax で POST されたデータを受けるためのメソッド。 // public static にして WebMethodAttribute 属性を付与 [WebMethod] public static string ReceiveData(string postedData) { // サーバーでの何らかの処置 return postedData + " を処理しました。"; } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1"/> <title>Bootstrap Modal Demo</title> <!-- Bootstrap --> <link href="/bootstrap-3.2.0-dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <![endif]--> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="/Scripts/jquery-1.11.1.js" type="text/javascript"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="/bootstrap-3.2.0-dist/js/bootstrap.js" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ $(document).ready(function () { $("#DropDownList1").change(function () { var str = $("#DropDownList1 option:selected").val() + " " + $("#DropDownList1 option:selected").text(); $.ajax({ type: "POST", url: "0168-BootstrapModalsDropDownList.aspx/ReceiveData", data: '{"postedData":"' + str + '"}', contentType: "application/json; charset=utf-8", success: function (data) { // .NET 3.5 で追加された d パラメータの処置 if (data.hasOwnProperty('d')) { data = data.d; } $('#result').text(data); }, error: function (jqXHR, textStatus, errorThrown) { $('#result').text('textStatus: ' + textStatus + ', errorThrown: ' + errorThrown); } }); }); }); //]]> </script> </head> <body> <form id="form1" runat="server"> <input id="Button1" type="button" class="btn btn-primary btn-lg" value="Launch demo modal" onclick="$('#myModal').modal('show');"/> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"> <span aria-hidden="true">×</span> <span class="sr-only">Close</span> </button> <h4 class="modal-title" id="myModalLabel">Modal title</h4> </div> <div class="modal-body"> Modal Body… <br /> <asp:DropDownList id="DropDownList1" runat="server"> <asp:ListItem Value="00" Text="Red" /> <asp:ListItem Value="01" Text="Green" /> <asp:ListItem Value="02" Text="Blue" /> </asp:DropDownList> <div id="result"></div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal"> Close </button> </div> </div> </div> </div> </form> </body> </html>
クライアントスクリプトで DropDownList の選択結果(選択された Value と Text)を取得し、それを jQuery.ajax でサーバーに送信します。
非同期でクライアントから送信された DropDownList の選択結果は、.aspx ページに静的メソッドを追加してそれで受け、そのメソッドでサーバー側での処置を済ませたあと、"XXXを処置しました。" という文字列を返しています。
クライアント側でその文字列を受け取ると、Modal の中の div 要素に表示するようにしています。
実行結果は以下の画像のようになります。
http://surferonwww.info/BlogEngine/image.axd?picture=2016%2f9%2fbootstrapmodal.jpg
投稿2016/10/01 07:27
編集2016/10/01 07:33退会済みユーザー
総合スコア0
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/02 03:54
退会済みユーザー
2016/10/02 04:39
2016/10/03 12:21
0
ベストアンサー
DropDownListコントロールをUpdatePanelコントロールで囲んで部分更新するのはいかがでしょうか?
UpdatePanelコントロールならページ更新にならないので、ページが初期化されることがないので、ページ表示後に作られる擬似モーダルウィンドウは消えないと思いますが。
投稿2016/10/01 02:01
総合スコア314
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/02 03:50
2016/10/03 00:46
2016/10/03 12:23
あなたの回答
tips
太字
斜体
打ち消し線
見出し
引用テキストの挿入
コードの挿入
リンクの挿入
リストの挿入
番号リストの挿入
表の挿入
水平線の挿入
プレビュー
質問の解決につながる回答をしましょう。 サンプルコードなど、より具体的な説明があると質問者の理解の助けになります。 また、読む側のことを考えた、分かりやすい文章を心がけましょう。