2 回答

TA貢獻1831條經驗 獲得超10個贊
您可以使用AJAXUpdatePanel作為下面的示例,以消除每次回發(fā)時刷新整個頁面的要求,并允許針對您的情況局部渲染特定區(qū)域,這將成為模態(tài)主體。
的HTML
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<%-- AJAX UpdatePanel section--%>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</form>
背后的代碼
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Bind DropDownList1 with some testing data
DropDownList1.Items.Add(new ListItem() { Text = "Item 001", Value = "1" });
DropDownList1.Items.Add(new ListItem() { Text = "Item 002", Value = "2" });
DropDownList1.Items.Add(new ListItem() { Text = "Item 003", Value = "3" });
DropDownList1.Items.Add(new ListItem() { Text = "Item 004", Value = "4" });
DropDownList1.Items.Add(new ListItem() { Text = "Item 005", Value = "5" });
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = DropDownList1.SelectedValue;
}

TA貢獻1860條經驗 獲得超8個贊
最終弄清楚了這個問題。該問題是由顯示列表框的下拉菜單引起的。只要在列表框中單擊任何內容,下拉菜單就會關閉,并且基本上使選擇無效并關閉模式。我不得不停止傳播下拉列表。一旦我做到了,UpdatePanel就完成了它的工作。我在下拉菜單中添加了一個ID,并使用以下代碼來防止在單擊ListBox時將其關閉。
$('#myDropdown .dropdown-menu').on({
"click": function (e) {
e.stopPropagation();
}
});
我希望這對其他人有幫助??鞓返木幋a。
- 2 回答
- 0 關注
- 188 瀏覽
添加回答
舉報