ASP.NET
  Home arrow ASP.NET arrow Page 4 - Classes and ASP.NET AJAX
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

Classes and ASP.NET AJAX
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2008-06-19

    Table of Contents:
  • Classes and ASP.NET AJAX
  • Accessing base methods
  • Interfaces
  • Client Versions of .NET Classes
  • Enumerations

  • 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


    Classes and ASP.NET AJAX - Client Versions of .NET Classes


    (Page 4 of 5 )

    In addition to adding OOP-like features for JavaScript coding, ASP.NET AJAX achieves two goals through client class implementions that are analogs of some .NET classes:

    1. Functionality missing in JavaScript is provided as part of ASP.NET AJAX.
    2. .NET developers with little JavaScript experience can use some familiar elements in their code.

    In my opinion, this is one of the areas where upcoming ASP.NET AJAX versions will most certainly add more features, so the following list of classes is neither exhaustive nor final. Two useful features that are already available areSys.StringBuilderand enumerations.

    Sys.StringBuilder

    One of the new features introduced in .NET 1.0 that really improved performance was the introduction of the StringBuilder class. The downside, however, is that applications are usually full of code such as that illustrated below:

      string s = "", t;
      while (){
        t = <value>;
        s += t;
     
    }

    The problem lies in the statements += t, which is equivalent tos = s + t. Whenever this code is executed, a copy ofsand a copy oftare created in memory, concatenated, then saved back intos. However, it’s inefficient to create a copy ofsto achieve these results. Therefore,StringBuilderuses an optimized algorithm for string concatenation.

    In JavaScript, this approach does not have any measurable effect on memory (in fact, the implementation seems to be a tick slower than the standard approach). Then again, performance is not as critical an issue for client script as it is for server code. Nevertheless, for consistency with your server coding techniques, you can rely on your knowledge of .NET coding techniques and useStringBuilder on the client. Example 4-5 puts the StringBuilder class to work. It concatenates some strings to build an HTML chessboard.

    Example 4-5. Using an ASP.NET AJAX StringBuilder

    ClientStringBuilder.aspx

    <%@ Page Language="C#" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server">
      <title>ASP.NET AJAX</title>

      <script language="Javascript" type="text/javascript">
     
    window.onload = function() {
        var sb = new Sys.StringBuilder();
        for (var i = 8; i >= 1; i--) {
          for (var j = 97; j <= 104; j++) {
            sb.append(String.fromCharCode(j));
            sb.append(i);
            sb.append(" ");
          }
          sb.appendLine();
          sb.appendLine();
       
    }
        document.getElementById("output").innerHTML = "<pre>" +
    sb.tostring() + "</pre>";
     
    }
      </script>
    </head>
    <body>
      <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <div id="output"></div>
      </form>
    </body>
    </html>

    The built-in JavaScript functionString.fromCharCode()converts an ASCII code to its associated character, so the innerforloop runs from"a"through"h". As Figure 4-3 reveals, the code in Example 4-7 creates a simple chessboard.


    Figure 4-3.  A chessboard (with some potential)

    More ASP.NET Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Programming ASP.NET AJAX," published by...
       · Please provide above code using what purpose how to execute in ASP.NET
     

    Buy this book now. This article is excerpted from chapter four of Programming ASP.NET AJAX, written by Christian Wenz (O'Reilly, 2007; ISBN: 0596514247). Check it out today at your favorite bookstore. Buy this book now.

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