Thursday, March 22, 2012

Html controls vs. Web controls

Can someone give me some examples if when it is best to use html controls over web controls and vice versa?

Thanks,
tdnxxx444Web controls show up as <asp:class runat=server> (the "asp" may be replaced by other prefixes). They may have a corresponding HTML tag that they represent, but generally they are there to build all the HTML necessary for an idea. For example, something simple like the CheckBox web control still outputs several tags when you View Source: <span><input type=checkbox><label for>. Something like the Calendar control generates an enormous about of HTML.

An HTML control is really a direct match to an HTML tag, with the addition of 'runat=server' and usually the ID= attribute. For example, the checkbox appears as:
<input type="checkbox" runat=server id="Checkbox1" /
Most often, you will use WebControls. Usually you use HtmlControls when you write the HTML tag directly into your web form then decide that you want to access it programmatically or from a WebControl by its ID. Until you add "runat=server", the HTML is just text on the page. That "runat=server" makes the server side code be able to access an object representing that text. That object is a member of the HtmlControls classes.

No comments:

Post a Comment