单选按钮、列表视图和分组,天哪!
我正在开发一个项目,需要将 RadioButton 放入 ListView 中,并让它们都具有相同的 GroupName。 (不能使用RadioButtonList,说来话长)。
无论如何,这似乎是 .NET 中的一个众所周知的错误,因此我实现了此处找到的解决方案:
ASP.NET RadioButton 弄乱了名称(组名)
工作完美,但有一个小错误,毫无疑问它会回来咬我。如果我单击一个单选按钮,然后在 javascript 函数仍在运行且尚未完成时单击另一个单选按钮;我可以在同一组中选择 2 个单选按钮。
有什么想法吗?如果您需要澄清;给我留言,我会更新我的帖子。
编辑:我相信我在这里解决了自己的问题。请参阅下面我发布的答案。
I've got a project I'm working on where I need to put a RadioButton inside a ListView, and have them all have the same GroupName. (can't use RadioButtonList, long story).
Anyway, this seems to be a well known bug in .NET, so I've implemented the solution found here:
ASP.NET RadioButton messing with the name (groupname)
This works perfectly, but with one small bug which undoubtedly will come back to bite me. If I click one radio button, and then click another while the javascript function is still running and has not completed; I can get 2 radiobuttons in the same group selected.
Any ideas? If you need clarification; leave me a comment and I'll update my post.
EDIT: I believe I fixed my own issue here. See my posted answer below.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样的东西会起作用吗?
我承认我没有做很多研究,但这就是我通常解决此类问题的方式。
Would something like this work?
I admit I didn't do alot of research, but this is how I've usually solved this type of problem.
原来我在这里被误导了。
稍后在页面生命周期中;我添加了一个额外的 onclick 事件来覆盖以前的值。
在以下示例中:
onlcick 属性设置为“test2”; test1 丢失。
我最终通过附加到现有属性来修复它;见下文:
这可以正常工作。
Turns out I was misguided here.
Later on in the page lifecycle; I was adding an additional onclick event that was overwriting the previous value.
In the following example:
the onlcick attribute is set to "test2"; test1 is lost.
I ended up fixing it by appending to the existing attribute; see below:
This works without issue.