三级CascadingDropDown未将SelectedValue传递给Ajax调用

时间:2012-10-10 19:59:30

标签: asp.net .net vb.net cascadingdropdown

我正在尝试使用ASP.NET CascadingDropDown 控件来呈现值和用户选择的答案。前两个下拉列表始终显示用户上次访问页面时选择的答案。我还可以选择新值并保存它们,并将它们正确存储在数据库中。问题是,下次我来到此页面编辑下拉值时,前两个正确显示用户选择的答案,但第三个没有)。

如何正确显示第三个下拉菜单?调试时,看起来所选的值不会传递给服务器上的GetTaxo方法。

我正在使用转发器输出包含以下内容的自定义控件:

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

在代码隐藏中我设置了类别和 CascadingDropDown 的SelectedValue:

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

当呈现页面时,我发现没有问题,因为设置了SelectedValue。使用Category = 5149的下拉列表,但似乎没有将它的SelectedValue传递给服务器:

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'));
}

1 个答案:

答案 0 :(得分:0)

我最后使用ContextKey属性将答案传递给服务器。它重复了knownCategoryValue的目的,但是这个控件很好用,我需要完成它,所以我最终使用了contextKey来选择正确的答案。