0

我正在尝试使用 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'));
}
4

1 回答 1

0

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

于 2012-10-12T20:18:22.193 回答