对于下面这段代码:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>1</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="DropDownList1_SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
会报“对于 UpdatePanel“UpdatePanel1”中的触发器,未能在关联的控件“DropDownList1”上找到名为“DropDownList1_SelectedIndexChanged”的事件”的问题,网上很多解决办法是后台注册触发器。
但如果是带母版、并且在母板上已经放了一个ScriptManager的情况,这里就不能再用ScriptManager做注册了,因为不允许放两个ScriptManager。这个问题纠结了好一段时间。
后面摸索出来的解决办法是:DropDownList1我只定义了一个事件,那么干脆就不定义EventName了,Triggers代码改成下面这样子,就可以正常运行了。
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" />
</Triggers>