私は次のようにASP.NETのUpdatePanelを持っている:jQueryのダイアログの '閉じる' 紛争
<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<%-- jQuery dialog - Suppliers --%>
<div id="divSuppliers" style="display: none;">
<asp:ListBox ID="lstSuppliers" runat="server" SelectionMode="Single" Rows="10" Width="100%"
DataValueField="SupplierID" DataTextField="SupplierName">
</asp:ListBox>
<br /><br />
<asp:Button ID="btnSelectSupplier" runat="server" Text="Select 2" OnClick="btnSelectSupplier_Click" />
</div>
<asp:GridView ID="gvSuppliers" runat="server" AutoGenerateColumns="false" SkinID="gvSkin"
DataKeyNames="SupplierID" EmptyDataText="No Existing User Roles">
<Columns>
<asp:TemplateField HeaderText="Supplier Name">
<ItemTemplate>
<asp:Label ID="lblSupplierName" runat="server" Text='<%# Eval("SupplierName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="btnAddSupplier" runat="server" Text="Add Supplier"
Visible="false" OnClick="btnAddSupplier_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSelectSupplier" />
</Triggers>
</asp:UpdatePanel>
かなりシンプルな、本当に。 jQueryダイアログポップアップに使用するdiv、ASP.NETのGridViewコントロール(単一の列)、非同期ポストバック用のASP.NETボタン以外は何もありません。
ここには、btnSelectSupplierの非同期ポストバックを処理するclickイベントがあります。
protected void btnSelectSupplier_Click(object sender, EventArgs e) {
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=
// WORKS JUST FINE
List<SupplierItem> suppliers = new List<SupplierItem>();
foreach (int i in lstSuppliers.GetSelectedIndices()) {
suppliers.Add(
new SupplierItem { SupplierID = Convert.ToInt32(lstSuppliers.Items[i].Value), SupplierName = lstSuppliers.Items[i].Text });
lstSuppliers.Items[i].Selected = false;
}
gvSuppliers.DataSource = suppliers;
gvSuppliers.DataBind();
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=
// DOES NOT WORK!!
string jq = "$('#divSuppliers').dialog('close');";
ScriptManager sm = ScriptManager.GetCurrent(this);
if (sm != null && sm.IsInAsyncPostBack) {
ScriptManager.RegisterClientScriptBlock(
this, typeof(Page), Guid.NewGuid().ToString(),
jq, true);
}
}
問題: GridViewのは、(上記のクリックイベントを参照)非同期ポストバック中にちゃんと更新します。しかし、jQuery Dialogは閉じることを拒否しています(上記のイベントを参照してください)。私はページ上のScriptManagerにjavascript(jquery)を登録していますので、実行してダイアログを閉じる必要がありますが、何らかの理由でそれはしません。
EDIT: jQueryダイアログを開き、それをモーダルにするコード。
protected void btnAddSupplier_Click(object sender, EventArgs e) {
lstSuppliers.ClearSelection();
lstSuppliers.DataSource = Suppliers.GetAllSuppliers();
lstSuppliers.DataBind();
string jq = "var dlg = $('#divSuppliers').dialog({ modal: true, draggable: true, title: 'Suppliers', width: 500 }); dlg.parent().appendTo($('form:first'));";
ScriptManager sm = ScriptManager.GetCurrent(this);
if (sm != null && sm.IsInAsyncPostBack) {
ScriptManager.RegisterClientScriptBlock(
this, typeof(Page), Guid.NewGuid().ToString(),
jq, true);
}
}
uのjqueryコードを表示できますか?私はこれを解決することができます... – Thulasiram
唯一の関連jQueryは、上記の私のコードに含まれています(クリックイベントコードを参照してください)。ダイアログクローズは何らかの理由で動作していません - それだけです。 – Jagd
Safari/ChromeのFirebugやデベロッパーコンソールのようなJSコンソールで '$( '#divSuppliers')ダイアログを実行しようとしましたか? –