Difference between server controls and webform controls.

Last post 02-04-2004 6:38 AM by SATPAL. 3 replies.

Sort Posts:

  • Difference between server controls and webform controls.

    09-24-2002, 1:36 AM
    • Member
      20 point Member
    • ishb
    • Member since 09-23-2002, 6:54 AM
    • Posts 4
    Give me the difference in detail about the server controls(HTML with runat=server attached) and web form controls(asp:xxx).

    We need indepth details about the difference to select which controls to use in our project.

    This details should contain the difference in process, loadding etc.


    Advance thanks for your help

    Shahul
  • Re: Difference between server controls and webform controls.

    09-24-2002, 8:25 AM
    • Contributor
      3,715 point Contributor
    • PaulWilson
    • Member since 06-25-2002, 11:32 AM
    • Woodstock/Atlanta, GA (USA)
    • Posts 745
    • ASPInsiders
    First some terminology:
    In ASP.NET, any tag with the runat=server attribute is a control, also called a server control.
    You can also dynamically add controls, and even static html becomes a control when parsed.
    You are specifically asking about the difference between the HtmlControls and WebControls,
    which are 2 namespaces provided by the framework that have very similar controls in them.
    They are all server controls by definition, and they are all controls used on web forms also.

    HtmlControls are designed to be identical to basic html tags in all features and functionality.
    Declaring an html tag as runat=server simply allows you to programatically access its value,
    and to take advantage of things like the new postback events and viewstate found in .NET.
    You will not see any changes in the somewhat odd naming conventions used with html tags,
    nor will you see advanced properties for colors, fonts, borders, and other style attributes.
    Thus, these are designed to be used just like standard html tags, with programmatic access.

    WebControls are designed to be more like windows controls, instead of just standard html.
    They usually have much richer visual properties, like the colors, fonts, borders, and others.
    They also offer a more standard object model, so you can be sure text is always called text.
    In some cases they also are quite complex, like the grid, calendar, and validation controls.
    They end up being rendered as html also, but with a lot of automatic styles and javascript.
    Some of the basic input controls differ only in the richer feature set and new object model.

    All controls, regardless of type, go through the exact same server events and processing.
    There is always a minimal performance hit when using any control, as opposed to just html,
    but HtmlControls vs. WebControls are nearly the same, so this is not really an issue here.
    The issue is always do you need a control at all, i.e. are you going to do any programmatic
    access of the control or otherwise take advantage of postback events, viewstate, validation.
    If you need these features, then be assured that they still run faster than classic ASP did.

    Your choice between HtmlControls and WebControls should therefore come down to style.
    Are you an html coder, possibly writing your own code stylesheets for any rich interface?
    Are you needing to finely control all the html that is rendered, for cross-browser issues?
    If you answered yes to one of these questions then you mostly need to use HtmlControls.
    Are you wanting to do quick VB-like drag-n-drop of rich controls with lots of properties?
    Are you needing to build an intranet app or prototype where exact html doesn't matter?
    If you answered yes to one of these questions then you mostly need to use WebControls.

    Keep in mind that sometimes you don't have such an easy choice if you use HtmlControls.
    I prefer HtmlControls mostly, but if I need to do validation then I mostly use WebControls,
    unless I have a client that insists on client javascript that supports Netscape as well as IE.
    Also, you don't have anything compex, like grids and calendars, when using HtmlControls,
    so you will have to decide to do it yourself, like in classic ASP, or switch to WebControls.
    Thanks, Paul Wilson, ASPInsider, MC**

    For the best .NET code, examples, and tools, visit:
    WilsonDotNet.com, WilsonWebPortal.com, ORMapper.net
  • Re: Difference between server controls and webform controls.

    09-26-2002, 6:49 AM
    • Member
      20 point Member
    • ishb
    • Member since 09-23-2002, 6:54 AM
    • Posts 4
    Thanks Paul

    Shahul
  • Re: Difference between server controls and webform controls.

    02-04-2004, 5:56 AM
    • Member
      65 point Member
    • SATPAL
    • Member since 02-03-2004, 6:53 AM
    • Posts 13
    they sOO badly dont work the same....

    c:\inetpub\wwwroot\default.aspx.cs(75): Argument '1': cannot convert from 'System.Web.UI.HtmlControls.HtmlInputText' to 'string'

    use textfield.value to combat. i just figured it out....just thought a complete novice like me would appreciate this.
Page 1 of 1 (4 items)