2.9 WebControls versus HtmlControls


One of the first questions many people ask when they see that ASP.NET provides two sets of controls is, Which set of controls should I use? The answer depends on your needs. For most developers, it will be simpler to work with the WebControls hierarchy of controls because they are most like the desktop equivalents that most programmers are familiar with. They are also more uniform in their treatment of attributes. For example, every WebControl exposes a CssClass attribute providing a hook to a style-sheet style, but none of the HtmlControls expose such an attribute. Thus, to associate a style-sheet class with an HtmlControl , you must programmatically populate the Attributes collection with a name/value pair consisting of the string "class" and the name of the style-sheet class.

The two primary reasons for using HtmlControls are porting and using alternate designers. It may be simpler to port existing ASP or plain HTML pages to ASP.NET by selecting a subset of the elements on a form to run on the server by just adding the runat =server attribute. A designer other than Visual Studio .NET may be simpler to work with if the HtmlControls are used instead of the WebControls , because the designer is more likely to recognize familiar HTML elements. However, many of the most popular designers, including FrontPage and Dreamweaver, have announced support for ASP.NET WebControl elements. It is also not a matter of either/or, because WebControls can be freely mixed with HtmlControls , so if it makes more sense to use WebControls in one place and HtmlControls in another, feel free to do so.



Essential ASP.NET With Examples in C#
Essential ASP.NET With Examples in C#
ISBN: 0201760401
EAN: 2147483647
Year: 2003
Pages: 94
Authors: Fritz Onion

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net