cjo*_*080 6 updatepanel radiobuttonlist asp.net-ajax selectedindexchanged
我有一个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>
Run Code Online (Sandbox Code Playgroud)
在上面的代码示例中,当用户从默认选择(例如,"Master's Degree")切换到不同选项(例如,"Doctorate")时,则触发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>
Run Code Online (Sandbox Code Playgroud)
只有在我将第二个控件放在ASP.Net AJAX UpdatePanel中才能启用异步回发(如上所示)之后,我才会遇到这个问题.一旦我这样做,原始的RadioButtonList控件将仅在我选择当用户到达页面时未默认选择的ListItem时回发.如果用户随后选择原始默认选择,则不会发生回发.
为了澄清,如果我回发而不将适用的第二个控件放在ASP.Net AJAX UpdatePanel中,那么无论用户选择哪个RadioButtonList ListItem,SelectedIndexChanged都可以工作.另一方面,在将控件放在UpdatePanel中以应用AsyncPostBackTrigger之后,回发仅针对非默认ListItem的选择.
可能相关的更多信息是我使用Microsoft Visual Studio 2008进行编码,而我正在使用的UpdatePanel控件是Microsoft AJAX Libary(不是ASP.NET AJAX Control Toolkit)的一部分.
我非常感谢有关如何使ASP.Net AJAX工作的任何见解,以便当用户选择RadioButtonList中的默认或非默认ListItem时,我可以触发SelectedIndexChanged事件.为了记录,我尝试在page_load事件中设置RadioButtonList默认选择,但它没有帮助.
在此先感谢您的帮助!
我遇到了同样的问题,发现生成的HTML在默认选择中没有单击处理程序。列表中的其他单选按钮都具有单击处理程序以调用__doPostBack。因此,我添加了以下jQuery:
$("#rbl input[checked]").click(function (e)
{
var id = e.target.id.replace('_', '$');
setTimeout(function () { __doPostBack(id, ""); }, 0);
});
Run Code Online (Sandbox Code Playgroud)
但是,即使ajax调用现在按预期方式工作,服务器端代码仍未执行selectedIndexChanged处理程序。
认为这可能是因为服务器知道默认选择是(是)并且看到发布的选择是相同的,所以认为所选索引没有更改,因此没有执行处理程序。
然后我以为,当选择其他无线电之一时,服务器应该已经通过viewstate记住了这一点。这使我想起我viewstatemode="Disabled"
放在单选按钮列表的容器中。因此,我viewstatemode="Enabled"
在单选按钮列表上进行了设置,它现在已按预期工作。
归档时间: |
|
查看次数: |
8298 次 |
最近记录: |