ASP CheckBox asp:CheckBox Component Attributes
As I was few days ago, trying to add some Attributes to the ASP .NET Components (ListBox, CheckBox ...etc) from the Code Behind, I came to a very "funny" thing about how the ASP.NET is placing the Attributes to the Output HTML Code.
If you have sample Default.aspx Page, with following lines:
<form id="form1" runat="server">
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
... and the Code Behind looks like this:
protected void Page_Load(object sender, EventArgs e)
After starting the page in Browser, the following Output HTML Code is generated by ASP.NET:
<span testAttribute="123abc" onChange="ChangeSomething();">
<input id="CheckBox1" type="checkbox" name="CheckBox1" onclick="DoSomething();" />
<input name="TextBox1" type="text" id="TextBox1" testAttribute="123abc" onClick="DoSomething();" onChange="ChangeSomething();" />
As you can see, the Output HTML Code has transformed Checkbox Component into one <span /> element which contains testAttribute and onChange, and one <input type="checkbox" /> element containing only onClick Attribute.
ListBox Component looks much better, it contains all Attributes are in the same HTML Element.