简体   繁体   English

RadioButtonList选择在AutoPostBack上无法正常工作

[英]RadioButtonList selection not working properly on AutoPostBack

I needed to set the AutoPostBack property to true in order for my SelectedIndexChanged event to fire each time a radio button item was selected. 我需要将AutoPostBack属性设置为true,以便每次选择单选按钮项时都触发我的SelectedIndexChanged事件。 Now for some reason if I click the second item or second to last item on the list, that I item never gets selected. 现在由于某种原因,如果我单击列表中的第二项或倒数第二项,则该项目永远不会被选中。 The screens flickers; 屏幕闪烁; postback, and either the first or last item on the RadioButtonList is selected instead. 回发,而是选择RadioButtonList的第一项或最后一项。

Is there a way to handle/prevent this from occurring? 有没有办法处理/防止这种情况发生?

There could be number of reasons why your code acting strange. 您的代码表现奇怪的原因可能有很多。 You could try following 您可以尝试关注

1) Check if the You might be missing the OnSelectedIndexChanged attribute in the definition of Radiobutton list. 1)检查您是否可能在单选按钮列表的定义中缺少OnSelectedIndexChanged属性。 Add OnSelectedIndexChanged="EventMethod" to RadioButtonList control definition. OnSelectedIndexChanged="EventMethod"添加到RadioButtonList控件定义。

2) EnableViewState may set to false on top of the page! 2)页面顶部的EnableViewState可能设置为false! Set it to true Add this line <%@ Page EnableViewState="true" > 将其设置为true添加此行<%@ Page EnableViewState="true" >

If none of above work kindly post Your source code so that missing part could be recognized. 如果以上工作均不愉快,请发布您的源代码,以便识别丢失的部分。

I see where the issue is now. 我看到了问题所在。 Tricky one to find. 棘手的发现。 It appears that because the first two items on my list have the same exact value, when the postback occurs it uses the selected value to set the item. 似乎因为列表中的前两个项目具有相同的确切值,所以发生回发时,它将使用选定的值来设置该项目。 To remedy the issue, I had to add some variation to the values when adding them to the RadioButtonList's list items, so that they are unique. 为了解决此问题,在将值添加到RadioButtonList的列表项时,我必须对值添加一些变体,以使它们唯一。 Issue solved! 问题已解决! :) I hope if anyone encountering this issue, this posting helps them out. :)我希望如果有人遇到此问题,这篇文章对他们有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM