Search code examples
asp.net.netvb.netcascadingdropdown

Third Level CascadingDropDown Not Passing SelectedValue to Ajax Call


I am attempting to use the ASP.NET CascadingDropDown control to render values and the answers the user selected. The first two dropdown's always show the answer the user selected the last time they visited the page. I am also able to select new values and save them and they are stored correctly in the database. The problem is the next time I come to this page to edit the drop down values the first two correctly show the answer the user selected but the third one does not).

How do I get this third drop down to show correctly? When debugging it looks like the selected value is not passed to the GetTaxo method on the server.

I am using a repeater to output a custom control that contains the following:

<asp:DropDownList id="cboResponse" DataTextField="lov_label" 
   DataValueField="lov_cd" EnableViewState="True" runat="server" />

<ajaxToolkit:CascadingDropDown ID="CDDL" runat="server" Category="-"
   EnableViewState="True" ServiceMethod="GetTaxo"
   ServicePath="/ajax/SaT.asmx" 
   TargetControlID="cboResponse" PromptValue="-1" PromptText="(Select One)" 
   LoadingText ="Loading..." />

In the code-behind I set the category and the CascadingDropDown's SelectedValue :

CDDL.Category = questionId
CDDL.SelectedValue = cboResponse.SelectedValue

When the page is rendered, I see no problem as SelectedValue is set. The dropdown with Category=5149 but it doesn't appear to pass it's SelectedValue to the server:

Sys.Application.add_init(function() {
    $create(AjaxControlToolkit.CascadingDropDownBehavior, {"Category":"4548","ClientStateFieldID":"ucInvEdit_ucQuestionRepeater_rptQuestions_ctl03_ctl02_CDDL_ClientState","LoadingText":"Loading...","PromptText":"(Select One)","PromptValue":"-1","SelectedValue":"MyAnswer","ServiceMethod":"GetTaxo","ServicePath":"/ajax/SaT.asmx","id":"ucInvEdit_ucQuestionRepeater_rptQuestions_ctl03_ctl02_CDDL"}, null, null, $get("ucInvEdit_ucQuestionRepeater_rptQuestions_ctl03_ctl02_cboResponse"));
});

document.getElementById('ucInvEdit_ucQuestionRepeater_rptQuestions_ctl03_ctl02_valSelectionRequired').dispose = function() {
    Array.remove(Page_Validators, document.getElementById('ucInvEdit_ucQuestionRepeater_rptQuestions_ctl03_ctl02_valSelectionRequired'));
}
Sys.Application.add_init(function() {
    $create(AjaxControlToolkit.CascadingDropDownBehavior, {"Category":"4025","ClientStateFieldID":"ucInvEdit_ucQuestionRepeater_rptQuestions_ctl04_ctl02_CDDL_ClientState","LoadingText":"Loading...","ParentControlID":"ucInvEdit_ucQuestionRepeater_rptQuestions_ctl03_ctl02_cboResponse","PromptText":"(Select One)","PromptValue":"-1","SelectedValue":"MyAnswer2","ServiceMethod":"GetTaxo","ServicePath":"/ajax/SaT.asmx","id":"ucInvEdit_ucQuestionRepeater_rptQuestions_ctl04_ctl02_CDDL"}, null, null, $get("ucInvEdit_ucQuestionRepeater_rptQuestions_ctl04_ctl02_cboResponse"));
});

document.getElementById('ucInvEdit_ucQuestionRepeater_rptQuestions_ctl04_ctl02_valSelectionRequired').dispose = function() {
    Array.remove(Page_Validators, document.getElementById('ucInvEdit_ucQuestionRepeater_rptQuestions_ctl04_ctl02_valSelectionRequired'));
}
Sys.Application.add_init(function() {
    $create(AjaxControlToolkit.CascadingDropDownBehavior, {"Category":"5149","ClientStateFieldID":"ucInvEdit_ucQuestionRepeater_rptQuestions_ctl05_ctl02_CDDL_ClientState","LoadingText":"Loading...","ParentControlID":"ucInvEdit_ucQuestionRepeater_rptQuestions_ctl04_ctl02_cboResponse","PromptText":"(Select One)","PromptValue":"-1","SelectedValue":"MyAnswer3","ServiceMethod":"GetTaxo","ServicePath":"/ajax/SaT.asmx","id":"ucInvEdit_ucQuestionRepeater_rptQuestions_ctl05_ctl02_CDDL"}, null, null, $get("ucInvEdit_ucQuestionRepeater_rptQuestions_ctl05_ctl02_cboResponse"));
});

document.getElementById('ucInvEdit_ucQuestionRepeater_rptQuestions_ctl05_ctl02_valSelectionRequired').dispose = function() {
    Array.remove(Page_Validators, document.getElementById('ucInvEdit_ucQuestionRepeater_rptQuestions_ctl05_ctl02_valSelectionRequired'));
}

Solution

  • I just ended up using the ContextKey attribute to pass the answer to the server. It's duplicating the knownCategoryValue's purpose but this control is flakey and I needed to get it done so I ended up using contextKey to get the correct answer selected.