ASP.NET
  Home arrow ASP.NET arrow Page 4 - 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 - The JavaScript Weakness


    (Page 4 of 5 )

    (3) Integrating JavaScript Frameworks

    Another problem with Web Forms is the integration of JavaScript frameworks due to the naming conventions of rendered HTML. The page life cycle of the Web Form is too complex and features tight coupling between everything in the ASP.NET framework; furthermore, a single class is used both to display output and handle user input. So unit testing is an almost impossible task. However, today unit testing is very important in modern software development, especially when we follow agile methodologies and practices. Since the web is a stateless thing, Events, Postbacks and ViewState are not a good way to go.

    As I've mentioned above, we can use Web Forms to freely control the HTML attributes and styles on the page. However, there is no doubt that we have no way (short of "hacking") to let the Web controls generate a simple ID. Here, let's take a TextBox control for example: although we specified its server side ID as txtUserName, the final client side ID might be LoginForm_txtUserName because it's within a NamingContainer whose ID is "LoginForm."

    With the appearance of the component model, there also arises tons of controls. We know that one of the main purposes of controls is multi-use, which in turn requires high cohesion that does not rest upon outside factors as much as possible. Therefore, to generate a unique ID on the client side for the related server side control, Web Forms introduces a new concept-NamingContainer. Server controls inside a NamingContainer will result in a client-side ID prefixed with the NamingContainer-provided rules. In this way, the client-side ID can be made unique.

    Another typical example relates to AJAX, a JavaScript technique implemented on the browser side. In AJAX-associated programming, we usually work with various DOM elements using JavaScript. In a non-Web Forms page, we can write something like the following:

    <input type="text" id="textBox" />

    <script language="javascript" type="text/javascript">

    document.getElementById("textBox").value = "Hello World!";

    </script>

    However, due to the NamingContainer, when we use Web Forms-related server controls, it might be impossible to locate the textbox element (the result <input />) through the TextBox server control. To overcome this problem, the server control model introduces a ClientID property through which we can acquire the client-side ID on the server side. For example, if you put the above code inside a user control, you should write it like this:

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

    <asp:TextBox runat="server" ID="textBox" />

    <script language="javascript" type="text/javascript">

    document.getElementById("<%= this.textBox.ClientID %>").value = "Hello World!";

    </script>

    When the control is put on a page, the client-side related result code should look like this:

    <input name="DemoControl1$textBox" type="text" id="DemoControl1_textBox" />

    <script language="javascript" type="text/javascript">

    document.getElementById("DemoControl1_textBox").value = "Hello World"!;

    </script>

    Please take notice of the name and id property of the above <input /> element here, all of which are in relation to marks left by NamingContainer. However, because we've used the <%= %> mark on the page to directly control the ID property of the server control, we can access the corresponding <input /> element related to the server side TextBox control using client-side JavaScript.

    As you've seen above, this kind of peculiar client-side ID is difficult to forecast in the design; it is just the so-called "client-side ID pollution" caused by using Web Forms.

    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 1 Hosted by Hostway
    Stay green...Green IT