Results 1 to 7 of 7

Thread: web forms html or server controls?

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    web forms html or server controls?

    being new to ASP.NET, whats the deal with the runat server controls like the command button versus the HTML controls like the button and textbox, etc...

    when should one be used versus the other?

  2. #2
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    .net controls can maintain state unlike their HTML equivalents so after you have filled in a .net textbox and submitted it to the server, when the control is rendered in your browser again the text box still has it's contents.

    .net controls also have properties which can be altered in code like .text .enabled . visible e.t.c.

    They can also fire off events like windows controls so selecting something from a listbox can fire off the index_changed event and so on.

    I moved over to .net from asp and found it very wierd to begin with but it is so much better and faster.

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    so why would you ever want to use regular HTML controls if they have replaced most of them with ASP.NET controls?

  4. #4
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    .net controls are heavier so if you don't need any of the features of the .net controls then use HTML.

    I never use HTML controls unless I need a textbox of File type.

  5. #5
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    Keep in mind, server processing is expensive. So if you don't need the functionality .net controls and code offer, then don't waste it. Because what your .net server has to do is render everything into HTML and send it to the client. When you view the source of a .aspx page while browsing, it looks totally different than your source because it's HTML.

    Just a side note but you can do a lot of cool stuff with client-side Javascript (like alerts or popup windows) that you just can't do with server-side code. A good rule is anything you can do on the client, do it.

  6. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Just a sample reason:

    IF you have a window that pop's up, and you have a Close button on that window, you could make it either a .Net Button, or use a simple <input type=button tag.>

    Having the close button as a .Net Button means the server goes through the trouble of instantiating a button class, assigning any non-default properties, and calling the class's render method when it comes time to render the page, saving the control's viewstate to the page's statebag. Additionally, on post back, the server must re-construct the button, assign any viewstate...etc...

    With a simple <input type=button> tag, the server just writes the html out, no implicit processing....

    So, for a Close button, you only need an input tag, assigning window.close to its onclick event. Since you won't change the text on the control, and won't change its functionality, dependant on some data or anything.

  7. #7
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Originally posted by wey97
    ... A good rule is anything you can do on the client, do it.
    Be careful with that rule, JavaScript isn't always enabled on the client, so have backup plans.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width