0
我有一個DynamicPopulateExtender控件,我希望它根據asp:DropDownList的值來呈現html。問題是如何編寫抓取下拉值的JavaScript,將其分配給DynamicPopulate控件的contextKey,然後觸發更新。動態更新DynamicPopulateExtender與DropDownList值的ContextKey
當我到達JavaScript中的populate()方法時,目前我的代碼凍結,所以我認爲我的JavaScript需要一些工作。
這裏是我的DropDownList的擴展,我想更新面板:
<asp:DropDownList id="cboResponse" cssclass="DataControl" DataTextField="lov_label" DataValueField="lov_cd" runat="server" />
<asp:Panel ID="pSectFunc" runat="server" />
<ajaxToolkit:DynamicPopulateExtender ID="DPE" runat="server" TargetControlID="pSectFunc" ServicePath="/ajax/SAT.asmx" ServiceMethod="GetPanelHTML" />
這裏是JavaScript我現在有。我可以從下拉到SERVICEID的價值,但我無法找到並使用正確的ContextKey調用擴展:
<script type="text/javascript">
function ValPickListSelection(val, args) {
args.IsValid = document.getElementById(val.controltovalidate).selectedIndex > 0;
}
//Need to update the contextKey of the DynamicPopulateExtender with the correct
//ServiceId so it can render the correct sector-function combination.
$(document).ready(function() {
$('#<%= cboResponse.ClientID %>').change(function() {
var dpe = $('#<%= DPE.ClientID %>');
var ServiceId = Number($(this).val());
if (ServiceId > 0) {
dpe.ContextKey = ServiceId;
dpe.populate();
}
});
});
</script>