Well, doing a very simple example renders the same span around the CheckBox, but the IDs are as I would expect. Simple setup...
<%@ Page language="c#" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
public void Page_Load(Object oSender, EventArgs eArg)
CheckBox box1 = new CheckBox();
box1.ID = "myID2";
box1.CssClass = "someclass";
HtmlInputText box2 = new HtmlInputText();
box2.ID = "myID1";
<form id="test" method="post" action="default.aspx" runat="server"/>
The span is still odd, but the IDs are fine. It renders (aligned nicer though)...
<form name="test" method="post" action="test.aspx" id="test">
<input type="hidden" name="__VIEWSTATE" value="dDw5NTgyNDg3OTY7O2w8bXlJRDI7Pj4zqu8pPRyb4gWRfNvIozI77yvCaQ==" />
<input id="myID2" type="checkbox" name="myID2" />
<input name="myID1" id="myID1" type="text" />
The problem now seems like it has to do with my structure. Basically I have a user control (.ascx), which are loaded dynamically, and in this there is a Label as a placeholder.
In code I make an instance of a class, which inherrits HtmlForm. The CheckBox in the first post was added to this class using the Controls collection of the base class HtmlForm. The class which inherrits HtmlForm is then added to the placeholder. This seems to work fine; i.e. login UI etc. works fine; i.e. except from the odd labeling and CSS classes.
I am not using DataGrid or DataAdapter. Simply adding dynamically instantiated CheckBox controls to an instance of a HtmlForm, and then adding it to the page.