ASP.NET单选按钮的名称搞乱(组名) [英] ASP.NET RadioButton messing with the name (groupname)

查看:79
本文介绍了ASP.NET单选按钮的名称搞乱(组名)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模板化控件(中继)上市的一些文字和其他标记。每个项目具有与其相关联的单选按钮,从而有可能为用户选择由中继创建的项目之一。

I got a templated control (a repeater) listing some text and other markup. Each item has a radiobutton associated with it, making it possible for the user to select ONE of the items created by the repeater.

中继器写入单选设置与ASP.NET的默认命名约定使每一个单选按钮一个完整的'小组'生成的ID和名称。这意味着所有单选按钮是独立于对方,这再次不幸意味着我可以在同一时间选择所有单选按钮。该单选按钮,用来设置一个共同的名字聪明属性'组名',使他们获得组合在一起,因此应该依赖(所以我只能选择一次)。问题是 - 这并不工作 - 中继确保id和由此而得名(控制组)是不同的。

The repeater writes the radiobutton setting its id and name generated with the default ASP.NET naming convention making each radiobutton a full 'group'. This means all radiobuttons are independent on each other, which again unfortunately means I can select all radiobuttons at the same time. The radiobutton has the clever attribute 'groupname' used to set a common name, so they get grouped together and thus should be dependant (so I can only select one at a time). The problem is - this doesn't work - the repeater makes sure the id and thus the name (which controls the grouping) are different.

由于我使用一个中继器(可能是一个列表视图或任何其他模板化数据绑定控件),我不能使用单选按钮列表。那么,这是否离开我?

Since I use a repeater (could have been a listview or any other templated databound control) I can't use the RadioButtonList. So where does that leave me?

我知道我已经有这个问题,解决它。我知道,几乎每一个ASP.NET程序员一定也曾经有过,所以我为什么不能谷歌和找到一个坚实的解决问题的办法?我碰到的解决方案来执行由JavaScript分组(丑陋!),甚至处理单选按钮非服务器控件,强迫我做了一个的Request.Form [名称] 读取状态。我也试图与覆盖上的 preRender 事件中的name属性实验 - 不幸的是,拥有的页面和母版再次重写这个名称,以反映全ID /名称,所以我结束与相同的错误的结果。

I know I've had this problem before and solved it. I know almost every ASP.NET programmer must have had it too, so why can't I google and find a solid solution to the problem? I came across solutions to enforce the grouping by JavaScript (ugly!) or even to handle the radiobuttons as non-server controls, forcing me to do a Request.Form[name] to read the status. I also tried experimenting with overriding the name attribute on the PreRender event - unfortunately the owning page and masterpage again overrides this name to reflect the full id/name, so I end up with the same wrong result.

如果你没有比我张贴更好的解决方案,你仍然非常欢迎发表您的想法 - 至少我要知道,我的朋友杰克'是正确的关于如何搞砸了ASP.NET有时;)

If you have no better solution than what I posted, you are still very welcome to post your thoughts - at least I'll know that my friend 'jack' is right about how messed up ASP.NET is sometimes ;)

推荐答案

谷歌夫:<一href=\"http://www.google.se/search?q=asp.net+radiobutton+repeater+problem&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla%3aen-US%3aofficial&client=firefox-a\"相对=nofollow> asp.net单选按钮转发问题

该ID识别码的确实是一个不幸的后果。我采取将创建一个 - 或采摘的许多可用的一个 - 在客户端上添加了同名支持自定义控制

Indeed an unfortunate consequence of the id mangling. My take would be creating a - or picking one of the many available - custom control that adds support for same name on the client.

这篇关于ASP.NET单选按钮的名称搞乱(组名)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆