Why does ASP.Net RadioButton and CheckBox render inside a Span?

前端 未结 7 1354
一个人的身影
一个人的身影 2020-12-08 00:12

I would expect this:




        
相关标签:
7条回答
  • 2020-12-08 00:59

    Web controls in the System.Web.UI.WebControls namespace may render differently in different browsers. You can't count on them rendering the same elements always. They may add anything that they think is needed to make it work in the specific browser.

    If you want to have any control over how the controls are rendered as html, you should use the controls in the System.Web.UI.HtmlControls namespace instead. That is:

    <input type="checkbox" id="CheckBox1" runat="server" class="myClass" />
    <input type="radio" name="RadioButton1" runat="server" class="myClass" />
    <input type="text" id="TextBox1" runat="server" class="myClass" />
    

    They will render just as the corresponding html element, with no extra elements added. This of course means that you will have to take responsibility for the browser compatibility, as the control doesn't. Also, those controls doesn't have all the features of the controls in the WebControls namespace.

    0 讨论(0)
提交回复
热议问题