Friday, October 12, 2007

Differences between using web controls and using HTML controls in dotnet application

This is a note on differences between using web controls and using HTML controls in dotnet application,which I feel more useful and sharing with you all.

The confusion that I had, and I think some of you may also have, is that why provide two type of controls that almost provide similar functionality, i.e. that both the controls are executed on the server side , both the controls are providing nearly similar events and have similar usage when creating forms or other pages. All this is true that both controls are nearly similar, but they have a vast difference that exists between them. The ASP .NET Server Controls are more rich in functionality as compared to their HTML Server Control counterparts. Let's take a look at some other differences that exist between these controls.

1. Control Abstraction:A HTML Server Control has similar abstraction with its corresponding HTML tag and offers no abstraction.ASP .NET Server Controls have higher level of abstraction. An output of an ASP .NET server control can be the result of many HTML tags that combine together to produce that control and its events.

2. Object Model:The HTML Server Controls follow the HTML-centric object model.ASP .NET Server Controls have an object model different from the traditional HTML and even provide a set of properties and methods that can change the outlook and behavior of the controls.


3. Browser Compatibility:The HTML Server Controls have no mechanism of identifying the capabilities of the client browser accessing the current page.ASP .NET Server Controls can however detect the target browser's capabilities and render themselves accordingly.


Despite the differences you can still use these controls together by mixing them in an ASPX form or page. These controls can also be used together in the build up of user controls that you can design according your requirements and needs. As far as the question which control to use when? is concerned, I would say that its up to you to decide that what you are comfortable with and what you can handle easily. If you want to convert your existing HTML based template pages to ASPX based pages then it would be better for you to convert the tagged HTML controls within them to HTML Server Controls as this would only require you to add the runat="server" attribute to them. If preparing new ASPX based template pages that you want to easily target browsers according to their capabilities, e.g. a page that can have the same view on a mobile phone as it has on the Internet Explorer, would require you to use the ASP .NET Server Controls.


I am listing some difference between these two types of controls, If you find any other point please add to this

1. Server Controls Trigger Server side events. Where as HTML controls only trigger client side events.
2. State ManagementServer Controls provides State Management - Data entered in a control is maintained across requests.State Management in HTML Controls can be achieved using Page-level scripts.
3. AdaptationServer controls automatically detects & adapts display appropriately.HTML Controls - No automatic detection is possible.
4. PropertiesServer controls - Provides a good set of properties that can be manipulated from server side code.HTML Controls - It has the basic set of HTML attributes attached to each element.
5.server control inherits from System.Web.UI.Webcontrols but html not