所以我有一个 UserControl
,上面有一些级联 DropDownList
。从列表 1 中选择会启用列表 2,列表 2 又会启用列表 3。在所有三个列表中做出选择后,您可以移至下一页。
DropDownList
都在 UpdatePanel
中。但是“下一页”按钮位于 UpdatePanel
之外。该按钮应该被禁用,直到所有三个列表都有一个选择,然后它应该再次被启用。但由于该按钮位于 UpdatePanel
之外,因此当我进行选择时它不会更新。 (编辑:“下一页”按钮位于还包含 UserControl
的页面上。)
我知道一种解决方法:
var scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(dropDownList1);
scriptManager.RegisterPostBackControl(dropDownList2);
scriptManager.RegisterPostBackControl(dropDownList3);
这确保在任何下拉列表更改时回发,以便按钮可以更新。但如果我这样做,我可能会通过首先删除 UpdatePanel
来简化。
是否有另一种方法,通过一些聪明的 JavaScript 或其他东西,我可以在 UpdatePanel
之外更新控件,而不必放弃 Ajax?
最佳答案
在下一个按钮周围放置一个 UpdatePanel 并为每个下拉菜单创建一个触发器,以便它触发异步回发。例如:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="dropDownList1" />
<asp:AsyncPostBackTrigger ControlID="dropDownList2" />
<asp:AsyncPostBackTrigger ControlID="dropDownList3" />
</Triggers>
关于c# - 在 UpdatePanel 之外更新控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/503662/