[英]How to prevent updating the content of the UpdatePanel from the PostBack of the page?
[英]How to prevent a dropdownlist from postback or updating inside an updatepanel when button is clicked
單擊按鈕時如何防止下拉列表回發或在更新面板中更新。 我這樣做是因為我有Java腳本使ddl成為可搜索的dropdownlist。 我在更新面板中有一些標簽,文本框,gridviews和下拉列表。 當我單擊查看按鈕下拉列表時,它會恢復為正常的下拉列表,而不是可搜索的下拉列表。
<div>
<asp:DropDownList ID="ddlSector" runat="server" Width="150px"></asp:DropDownList>
<asp:DropDownList ID="ddlCity" runat="server" Width="150px"></asp:DropDownList>
<asp:TextBox ID="txtStdID" runat="server" Width="92px" MaxLength="5"></asp:TextBox>
<asp:Button ID="btnView" runat="server" Text="View" onclick="btnView_Click" AccessKey="V"/>
<table>
<tr><td><b>Qualification</b></td><td><b>Exemption Type</b></td></tr>
<tr>
<td><asp:DropDownList ID="ddlQualification" class="chzn-select" runat="server" Width="225px" onselectedindexchanged="ddlQualification_SelectedIndexChanged"
AutoPostBack="false"></asp:DropDownList></td>
<td>
<asp:DropDownList ID="ddlExemType" runat="server" Width="225px">
</asp:DropDownList></td>
</tr>
</table>
</div>
<script src="../Searchable DDL/jquery.min.js"type="text/javascript"></script>
<script src="../Searchable DDL/chosen.jquery.js"type="text/javascript"></script>
<script type="text/javascript">
$(".chzn-select").chosen();
$(".chzn-select-deselect").chosen({ allow_single_deselect: true });</script>
即使沒有完整的PostBack,UpdatePanel中的所有內容仍然會刷新,因此DOM會丟失使用jquery修改的元素。
您還需要在異步PostBack之后調用創建可搜索下拉列表的函數。
<script type="text/javascript">
$(document).ready(function () {
createSearchDropDown();
});
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function () {
createSearchDropDown();
});
function createSearchDropDown() {
$(".chzn-select").chosen();
$(".chzn-select-deselect").chosen({ allow_single_deselect: true });
}
</script>
在javascript的pageLoad事件中編寫您的javascript函數。
它將始終在回發以及部分回發中執行。
查找以下功能代碼
function pageLoad() {
//This will ensure your code will run all the time
CreateDropdown();
InitializeDatePickers();
AssignPlugins();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.