asp.net 复选框的自定义属性:如何检索它?
我正在使用带有复选框项目模板的中继器。这是我的复选框模板:
<asp:CheckBox runat="server" ID="chkBox" Text='<%# Eval("Text") %>' Value='<%# Eval("Value") %>' />
现在,我知道 asp 复选框没有 value 属性,但我在某处读到,您可以将其放在那里,它会起到相同的作用。我得再查一下,看看我是否读错了。但是,万一可以将自定义属性放在那里,如何在代码后面检索它?创建页面后我查看了源代码,控件中没有显示“值”的属性。有什么想法吗?谢谢。
编辑:
我在这里看到您可以添加自定义属性:
http://www.daveparslow.com/2007/08/assigning-value-to-aspnet-checkbox.html
I am using a repeater with the Item Template of a checkbox. Here's my checkbox template:
<asp:CheckBox runat="server" ID="chkBox" Text='<%# Eval("Text") %>' Value='<%# Eval("Value") %>' />
Now, I know asp checkboxes do not have a value attribute, but I read somewhere that you can put that in there and it will work the same. I'll have to look it up again to see if I read it wrong. However, just in case it is possible to put the custom attribute in there, how do I retrieve it in code behind? I looked at the source after the page is created and there is no attribute in the control that says "value". Any ideas? Thanks.
EDIT:
Here's where I saw you can add the custom attribute:
http://www.daveparslow.com/2007/08/assigning-value-to-aspnet-checkbox.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过属性集合从服务器控件检索值。 但是,就您的情况而言
,作为建议和我的评论所述,如果您想要一个有效的页面,您应该将文档类型更改为 HTML 5 并在自定义属性上使用
data-
注释。You can retrieve values from your server controls through the attributes collection. In your case,
However, as a suggestion and as my comment states, if you want a valid page, you should change your doc type to HTML 5 and use the
data-
annotation on your custom attribute.