Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add (hidden) label for asp:CheckBox?

I ran chrome’s lighthouse accessibility test on a page I’m working on and it says

Form elements do not have associated labels

for all the checkboxes used on the page. They are in a large grid and have no labels.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Ex:

<asp:CheckBox ID="cbNotApplicable" runat="server" AutoPostBack="true" OnCheckedChanged="cbNotApplicable_CheckedChanged" onClick='javascript:needToConfirm = false;' ToolTip="Answer all questions Not Applicable" />

If I add a Text attribute, the accessibility warning goes away, but a <label> is added and visible, which I do not want.

enter image description here

Is there an alternate way to make the asp:CheckBox accessible?

>Solution :

Try this way

    <asp:Label ID="test" runat="server"
        AssociatedControlID="cbNotApplicable"> <asp:CheckBox ID="cbNotApplicable" runat="server" AutoPostBack="true" OnCheckedChanged="cbNotApplicable_CheckedChanged"
     onClick='javascript:needToConfirm = false;' ToolTip="Answer all questions Not Applicable" /> </asp:Label>

Or, try this below link suggestions to hide label by using CSS

https://stackoverflow.com/a/13482643/2218635

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading