【问题标题】:Third Level CascadingDropDown Not Passing SelectedValue to Ajax Call第三级 CascadingDropDown 未将 SelectedValue 传递给 Ajax 调用
【发布时间】:2012-10-10 19:59:30
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-16
      • 2020-01-21
      • 2012-02-10
      • 1970-01-01
      • 2014-07-18
      相关资源
      最近更新 更多