0

I have a DynamicPopulateExtender control and I want it to render html based on the value of an asp:DropDownList. The problem is how to write the javascript that grabs the value of the drop down, assigns it to the DynamicPopulate control's contextKey, and then triggers the update.

Currently my code freezes when I get to the populate() method in the JavaScript so I think my JavaScript needs some work.

Here is my DropDownList, the Extender, and the panel I want to update:

<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" />

And here is the javascript I currently have. I can get the value from the drop down into ServiceId but I am unable to find and invoke the extender with the correct 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>
4

1 に答える 1

0

DynamicPopulateExtenderのBehaviorID属性を設定する必要があります。次に、jQuery $ find()を使用して、コントロールへの参照を取得します。

<script type="text/javascript">
   $(document).ready(function () {
   $('#<%= cboResponse.ClientID %>').change(function () {
     var dpe = $find('DPE_Behavior');
     var contextKey = Number($(this).val());
       if (dpe) {
         dpe.populate(ServiceId);
       }
     });
   });
</script>
于 2012-12-17T18:28:53.140 に答える