How to remove span tag from WebControl when rendered

后端 未结 15 991
生来不讨喜
生来不讨喜 2020-12-31 03:34

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

15条回答
  •  忘掉有多难
    2020-12-31 04:25

    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:

    
    

    The last two will cause the wrapping span.

提交回复
热议问题