不是真正的答案,而是对其他建议的一些奇怪观察。我先说这是 ASP.Net 4.0 应用程序中的 RadioButtonList,RepeatDirection=Vertical
1) 添加 onclick='myJsFunction(this);'在页面上的不同项目导致回发(例如按钮操作)之后,ListItems 的属性对我来说效果很好除了,ListItems 上的属性不会被渲染 strong> 在回发的结果中。它们被渲染以开始,但不是在有按钮操作时。去图吧。
2) 显然,我们的遗留代码依赖于 RadioButtonList/ListItem 上的一些模糊的、不规范的行为,这些行为在回发时变得非常混乱。如果您在 ListItem 上放置 id 属性,ASP.Net 2.0+ 将在单选按钮周围添加 span 标记并将您的 id 值放在那里。如果您在其上添加 onclick 属性,该属性将出现在单选按钮上 - 至少在 Page.IsPostBack == false 时。
<asp:RadioButtonList ID="proceedChoice" runat="server" RepeatDirection="Vertical">
<asp:ListItem id="Close_Case_Y" Value="Y" onclick="SelectResolveType(this);" Text="I want to close this case." runat="server" />
<asp:ListItem id="Close_Case_N" Value="N" onclick="SelectResolveType(this);" Text="I want to cancel this and start over." runat="server" />
</asp:RadioButtonList>
呈现为
<table id="...proceedChoice" border="0">
<tr>
<td><span id="Close_Case_Y"><input id="..._proceedChoice_0" type="radio" value="Y" onclick="SelectResolveType(this);" /><label for="..._proceedChoice_0">I want to close this case.</label></span></td>
</tr><tr>
<td><span id="Close_Case_N"><input id="..._proceedChoice_1" type="radio" value="N" onclick="SelectResolveType(this);" /><label for="..._proceedChoice_1">I want to cancel this case and start over.</label></span></td>
</tr>
</table>
从其他按钮回发后,虽然相同的模板呈现为
<table id="...proceedChoice" border="0">
<tr>
<td><input id="..._proceedChoice_0" type="radio" value="Y" /><label for="..._proceedChoice_0">I want to close this case.</label></td>
</tr><tr>
<td><input id="..._proceedChoice_1" type="radio" value="N" /><label for="..._proceedChoice_1">I want to cancel this case and start over.</label></td>
</tr>
</table>
但真正奇怪的地方在于:如果您将除 id 和 onclick 之外的其他属性添加到 ListItem,只会保留那些 属性。例如,如果我将 hidden="hidden" 添加到 ListItems 之一,它会在回发后呈现如下
<table id="...proceedChoice" border="0">
<tr>
<td><span hidden="hidden"><input id="..._proceedChoice_0" type="radio" value="Y" /><label for="..._proceedChoice_0">I want to close this case.</label></span></td>
</tr><tr>
<td><input id="..._proceedChoice_1" type="radio" value="N" /><label for="..._proceedChoice_1">I want to cancel this case and start over.</label></td>
</tr>
</table>