ASP.NET
  Home arrow ASP.NET arrow Page 3 - ASP.NET Web Forms Weaknesses
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

ASP.NET Web Forms Weaknesses
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 4
    2008-11-11

    Table of Contents:
  • ASP.NET Web Forms Weaknesses
  • The HTML Tag Weakness
  • Code Explained
  • The JavaScript Weakness
  • Last Example

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    ASP.NET Web Forms Weaknesses - Code Explained


    (Page 3 of 5 )

    As you can see above, GridView generates a <table /> element with many ugly items in it. It's pretty difficult to control the style of the table. Although GridView provides detailed style definition from the title to each cell, there is far less flexibility. And also, the GridView control-generated HTML tags do not correspond to Web standards (e.g. cannot generate the <th/> tag).

    So, in this sense, we can complain about Web Forms, while at the same time we advocate rejecting the GridView-like complex controls (including DataList, FormView, etc.). Then a question arises: when GridView is rejected, what's the sense of still using Web Forms?

    In fact, the ViewState, Postback, and GridView are not all of Web Forms. In my opinion, the Control model (or the Component model) really represents the key part of Web Forms. As you may know, the infrastructure of this model is absolutely excellent. Now I will show you some related examples (although they are very elementary).

    First, let's take a look at the commonly-used DemoControl.ascx user control:

    <%@ Control Language="C#" AutoEventWireup="true" %>

    <%= "Hello World!" %>

    Then, we put it inside an .aspx page:

    <div>

    <uc1:DemoControl ID="DemoControl1" runat="server" />

    </div>

    When you launch the above page in a browser and view the related page source, you will get the following:

    <div>

    Hello World!

    </div>

    How clean the above code is!

    Another example is Master Page: its <asp:ContentPlaceHolder /> will not generate any redundant code. This proves an important fact that a web form based upon user controls will not produce useless and nasty code. Besides this, most of the fundamental controls, such as TextBox, CheckBox (not setting Text property), Panel, etc. will not produce useless code at all.

    So, where on earth did the above-mentioned "nasty" tags come from? As you may have guessed, they all resulted from complex server controls, such as GridView, FormView, and many Data controls. However, there is an exception among these complex controls-Repeater. The following gives an example of the Repeater control:

    <asp:Repeater runat="server" ID="rptItems">

    <HeaderTemplate>

    <ul>

    </HeaderTemplate>

    <ItemTemplate>

    <li>

    <img src="<%# Eval("ImagePath")) %>" alt="<%# Eval("Title") %>" />

    </li>

    </ItemTemplate>

    <FooterTemplate>

    </ul>

    </FooterTemplate>

    </asp:Repeater>

    When you watch the resulting HTML tags rendered on the browser side (herein we omit it), you will find there is also clean code generated for the Repeater control without even a line of useless code.

    With the release of ASP.NET 3.5, a new and powerful server control comes to you-ListView. Nowadays, you can easily find many examples related to this control, so we won't dwell on it here. However, there is an important point that  deserves to be emphasized: as with the Repeater control, ListView will lead to clean HTML marks, and you can manipulate its HTML contents all by yourself.

    To try to avoid using the GridView, DataList, and FormView. I highly recommend that you use Repeater and ListView as many as possible.

    More ASP.NET Articles
    More By Xianzhong Zhu


       · Excellent article! Ive been complaining about WebForms to senior C# people for years...
     

    ASP.NET ARTICLES

    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...
    - Building an In-Text Advertising System Under...
    - Developing a Mini ASP.NET AJAX Server Centri...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT