How to remove span tag from WebControl when rendered

后端 未结 15 984
生来不讨喜
生来不讨喜 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:16

    I don't know if this will work on this particular example. But if you make your own WebControl and you never want it to render spans around itself you can override the Controls render method like this:

    public class MyWebControl : WebControl
    {
    
      /* Your code 
                 between here */
    
      protected override void Render(HtmlTextWriter writer)
      {
        RenderContents (writer);
      }
    }
    

    I guess that you could add the same to an inherited CheckBox... something like this:

    public class MyCheckBox : CheckBox 
    {
    
      /* Your code 
                 between here */
    
      protected override void Render(HtmlTextWriter writer)
      {
        RenderContents (writer);
      }
    }
    

    The basic problem with the solution is better explained here:
    http://www.marten-online.com/net/stripping-span-tag-from-webcontrol.html

提交回复
热议问题