13

所以我有一个UserControl带有一些级联DropDownList的 s 。从列表 1 中选择会启用列表 2,而后者又会启用列表 3。在所有三个列表中做出选择后,您可以转到下一页。

DropDownLists 都在一个UpdatePanel. 但是“下一页”按钮在UpdatePanel. 应该禁用该按钮,直到所有三个列表都有选择,然后应该再次启用它。但由于该按钮位于 之外UpdatePanel,因此在我进行选择时它不会更新。(编辑:“下一页”按钮位于还包含的页面上UserControl。)

我知道解决这个问题的一种方法:

var scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(dropDownList1);
scriptManager.RegisterPostBackControl(dropDownList2);
scriptManager.RegisterPostBackControl(dropDownList3);

这样可以确保在更改任何下拉列表时进行回发,以便按钮可以更新。但是如果我这样做,我可能会通过首先摆脱 来简化UpdatePanel

有没有另一种方法,通过一些聪明的 JavaScript 或其他东西,我可以在UpdatePanel不放弃 Ajax 的情况下更新控件之外的控件?

4

4 回答 4

12

在下一个按钮周围放置一个 UpdatePanel 并为每个下拉菜单创建一个触发器,以便它触发异步回发。前任:

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="dropDownList1" />
    <asp:AsyncPostBackTrigger ControlID="dropDownList2" />
    <asp:AsyncPostBackTrigger ControlID="dropDownList3" />
</Triggers>
于 2009-02-02T16:05:13.767 回答
7

你不能在“下一页”周围添加一个更新面板,然后在下拉列表更新面板中添加一个触发器来触发下一页更新面板吗?

只是抛出想法,没有实际尝试过:)

于 2009-02-02T15:55:30.480 回答
2

您可以通过将控件放入 update_panel2 并说update_panel2.update().

请注意,UpdateMode必须将 UpdatePanel 的 设置conditional为才能正常工作。

于 2012-06-12T03:36:38.717 回答
1

理想情况下,这将在 javascript 中完成,并在 click 事件处理程序中进行服务器端验证检查。

一个快速的 jQuery 示例:

//assuming the dropdowns all have the css class "cascade"
$('select.cascade').change(function() {
  If ($('option:selected',this).length == 3) {
    $('input[id$=btnNext]').removeAttr('disabled');
  }
});
于 2009-02-02T16:05:09.290 回答