我有一个ASP.Net的RadioButtonList控件,其AutoPostBack属性设置为true。同时,当用户更改选择时会调用OnSelectedIndexChanged函数。最后,因为用户需要提供此控件所请求的信息,所以在用户进入页面时我设定了默认选择--
<asp:RadioButtonList ID="rblHighestDegree" runat="server" AutoPostBack="true"
onselectedindexchanged="rblHighestDegree_SelectedIndexChanged">
<asp:listitem Runat="server" Text="Master's Degree" Selected="True" />
<asp:listitem Runat="server" Text="Doctorate" />
</asp:RadioButtonList>
在上面的代码示例中,当用户从默认选择(例如,“硕士学位”)切换到其他选项(例如,“博士学位”)时,将触发SelectedIndexChanged事件。然后,如果用户改变主意,随后重新选择原始默认选项,则再次触发SelectedIndexChanged事件。这正如预期的那样完美地工作。
我有第二个控件,根据上述选择启用或禁用,在代码后台...
<asp:ScriptManager ID="scriptmanager1" runat="server" />
<asp:UpdatePanel ID="updatepanel1" runat="server">
<ContentTemplate>
<asp:RadioButtonList ID="rdlYearsOfStudy" runat="server" Enabled="false">
<asp:listitem Runat="server" Text="Less than 3 years" />
<asp:listitem Runat="server" Text="3 - 4 years" />
<asp:listitem Runat="server" Text="5 - 6 years" />
</asp:RadioButtonList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rblHighestDegree" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
我遇到的问题只发生在我将第二个控件放入ASP.Net AJAX UpdatePanel以启用异步PostBack之后(如上所示)。一旦我这样做,原始的RadioButtonList控件只有在选择了用户在页面上默认未选择的ListItem时才会PostBack。如果用户随后选择了原始默认选择,则不会发生PostBack。
为了澄清,如果我在不将适用的第二个控件放入ASP.Net AJAX UpdatePanel的情况下PostBack,则无论用户选择哪个RadioButtonList ListItem,SelectedIndexChanged都有效。另一方面,在我将控件放入UpdatePanel中以应用AsyncPostBackTrigger后,PostBack仅对非默认ListItems的选择发生。
更多相关信息是,我正在使用Microsoft Visual Studio 2008进行编码,我正在使用的UpdatePanel控件是Microsoft AJAX Library的一部分(而不是ASP.NET AJAX Control Toolkit)。
我希望能得到任何关于如何使ASP.Net AJAX起作用的见解,以便在用户选择默认或非默认ListItems时触发SelectedIndexChanged事件。值得一提的是,我尝试在page_load事件中设置RadioButtonList默认选择,但没有帮助。
感谢您提前提供的所有帮助!