Adding custom attributes to an asp:CheckBox control

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 23:40:23

问题


I am trying to add a custom data-required attribute to an asp Checkbox control, it works fine for all other controls I've used it on, but on checkboxs it renders the checkbox inside a span that has the custom attribute on. I've tried adding the attribute in the markup and tried adding it to the control in the code behind. Any ideas?


回答1:


use InputAttributes




回答2:


Here is the code I have used:

cb.InputAttributes.Add("data-group", "chkbox");

Then you can use JQuery to target all check-boxes.

 $("*[data-group='chkbox']").prop("checked", true);


来源:https://stackoverflow.com/questions/9939287/adding-custom-attributes-to-an-aspcheckbox-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!