ASP.NET
  Home arrow ASP.NET arrow Page 5 - 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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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 - Enumerations


    (Page 5 of 5 )

     

    Another .NET type that is emulated by ASP.NET AJAX for JavaScript is Enum. You can create a custom enumeration using the createEnum() method. The API for this changed quite a bit during the Atlas and ASP.NET AJAX development cycle. In its current form, you can create an enumeration as shown in the following listing, but you cannot iterate over it. You can create a namespace, if you wish to use one:

      Type.registerNamespace("ORA.MyEnums");

    Then, create the enum object, assigning it an (empty) function:

      ORA.MyEnums.Ajax = function() {};

    Next, define all values in the enumeration, using the syntax below:

      ORA.MyEnums.Ajax.prototype = {
        "Asynchronous": 0,
        "JavaScript": 1,
        "and": 2,
        "XML": 3
     
    };

    Finally, the enumeration needs to be registered:

      ORA.MyEnums.Ajax.registerEnum("ORA.MyEnums.Ajax");

    Example 4-6 shows a complete example that creates the enumeration and then accesses it.

    Example 4-6. Using an ASP.NET AJAX Enum

    ClientEnum.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">
      function pageLoad() {
       
    Type.registerNamespace("ORA.MyEnums");
        ORA.MyEnums.Ajax = function() {};
        ORA.MyEnums.Ajax.prototype = {
         
    "Asynchronous": 0,
          "JavaScript": 1,
          "and": 2,
          "XML": 3
       
    };
        ORA.MyEnums.Ajax.registerEnum("ORA.MyEnums.Ajax");

        document.getElementById("output").innerHTML +=
          ORA.MyEnums.Ajax.Asynchronous + " " +
          ORA.MyEnums.Ajax.JavaScript + " " +
          ORA.MyEnums.Ajax.and + " " +
          ORA.MyEnums.Ajax.XML;
     
    }
      </script>

    </head>
    <body>
      <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <div id="output"></div>
      </form>
    </body>
    </html>

    This code outputs the string"0 1 2 3 "(the keys for the enumeration entries) in the<div>element.

    Enumerations are also used internally by ASP.NET AJAX to define mouse button values (the following code snippet has been edited and reformatted for clarity).

      Sys.UI.MouseButton = function() { };
      Sys.UI.MouseButton.prototype = {
        leftButton:0,
        middleButton:1,
        rightButton:2
     
    };
      Sys.UI.MouseButton.registerEnum("Sys.UI.MouseButton");

    Summary

    The ASP.NET AJAX client script library implements several convenient features not present in standard JavaScript, including OOP-like functionality and client-side equivalents of .NET Framework features. These features can be used by any JavaScript programmer, without repercussions to ASP.NET or the server-side features of ASP.NET AJAX.

    For Further Reading

    http://www.kevlindev.com/tutorials/javascript/inheritance
       Online tutorial for JavaScript’s OOP capabilities

    http://aspnetresources.com/blog/ms_ajax_cheat_sheets_batch2.aspx
      
    “Cheat sheets” for ASP.NET AJAX’s JavaScript
       extensions

    http://ajax.asp.net/docs/ClientReference/Global/default.aspx
       Documentation for helper functions and JavaScript
       base type extensions

    http://quickstarts.asp.net/Futures/ajax/doc/cssselectors.aspx
       The ASP.NET AJAX Futures provides JavaScript helper
       functions to select elements based on CSS rules  


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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

    - Developing a Mini ASP.NET AJAX Server Centri...
    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




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