Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove span tag from WebControl when rendered

When using an ASP.NET CheckBox (and in out case, inherited from a CheckBox) it renders a span around the checkbox input control, this span control is affecting jQuery scripts.

Is it possible to remove this span when rendering?

like image 638
Mark Redman Avatar asked Jan 31 '10 21:01

Mark Redman


1 Answers

Found this useful tip:

In Code Behind, use InputAttributes instead of Attributes.

For Example, type this:

chk.InputAttributes.Add("onchange", "updateFields()")

instead of this:

chk.Attributes.Add("onchange", "updateFields()")

or instead of inline declarations:

<asp:CheckBox ID="chk" runat="server" onchange="updateFields()" />

The last two will cause the wrapping span.

like image 59
Jon Avatar answered Oct 17 '22 06:10

Jon