ASP.NET
  Home arrow ASP.NET arrow Page 2 - 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 - Accessing base methods


    (Page 2 of 5 )

    When we talk about class inheritance, a logical question is whether methods can be overridden in derived classes. The answer is yes. The next question: is there any way to access the equivalent method of the base class, (i.e., the overridden method)? Even better, the answer is again yes, ASP.NET AJAX allows you to do so. To demonstrate this, let’s add a toString() method to OReilly.Softwarethat outputs the product and vendor names stored by the class. Theprototypeproperty ensures automated inheritance and also helps demonstrate access to the base method later on.

      OReilly.Software.prototype.toString = function() {
       
    return this.getName() + " from " + this.getVendor();
      }

    You could also directly access the properties_nameand_vendoras variables. Using the getter methods is just a personal preference. There is no functional difference in doing so.

    In theOReilly.Browserclass, you could write a similartoString()method:

      OReilly.Browser.prototype.toString = function(){
        return this.getName() + " from " + 
    this.getVendor() +
               (this.getIsJavaScriptSupported() ? " (w/ JS)" : " (w/o JS)");
      }

    However, it is once again advisable to reuse existing code, in this case, the base class’stoString()method. ASP.NET AJAX provides you withcallBaseMethod(), a helper method to call a method from the parent class that can take up to three parameters:

    instance
      
    The instance whose parent’s method to call (usually
       this)

    methodName
      
    The name of the method (as a string)

    baseArguments
       Parameters for the method, if any (as an array)

    In this case, thetoString()method ofOReilly.Browsercan be implemented as the following code demonstrates:

      OReilly.Browser.prototype.toString = function() {
        return OReilly.Browser.callBaseMethod(this, "toString") +
               (this.getIsJavaScriptSupported() ? " (w/ JS)" : " (w/o JS)");
      }

    Now, the code to output the browser information can be reduced a bit to these commands below:

      var s = "";
      var ie = new OReilly.Browser("Internet Explorer", "Microsoft", true);
      s = ie.toString() + "<br />";

      var lynx = new OReilly.Browser("Lynx", null, false);
      s += lynx.toString();
      document.getElementById("output").innerHTML = s;

    Example 4-3 shows the complete listing.

    Example 4-3. Accessing a base class method

    ClientBaseMethods.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() {
        var s = "";

        Type.registerNamespace("OReilly");
       
    OReilly.Software = function(name, vendor) {
          var _name = (name != null) ? name : "unknown";
          var _vendor = (vendor != null) ? vendor : "unknown";

          this.getName = function() {
           
    return _name;
          }
          this.setName = function(name) {
            _name = name;
          }

          this.getVendor = function() {
           
    return _vendor;
          }
          this.setVendor = function(vendor) {
            _vendor = vendor;
         
    }
        }
        Type.registerClass("OReilly.Software");

        OReilly.Browser = function(name, vendor, isJavaScriptSupported) {
          OReilly.Browser.initializeBase(this, new Array(name, vendor));
          var _isJavaScriptSupported = (isJavaScriptSupported != null) ?

    isJavaScriptSupported : false;
          this.getIsJavaScriptSupported = function() {
           
    return _isJavaScriptSupported;
            }
            this.setIsJavaScriptSupported = function(isJavaScriptSupported) {
             
    _isJavaScriptSupported = isJavaScriptSupported;
          } 
       
    }
       OReilly.Browser.registerClass("OReilly.Browser", OReilly.Software);

        OReilly.Software.prototype.toString = function() {
          return this.getName() + " from " + this.getVendor();
          } 

         OReilly.Browser.prototype.toString = function() {
            return OReilly.Browser.callBaseMethod(this, "toString") + 
             (this.getIsJavaScriptSupported() ? " (w/ JS)" : " (w/o JS)");
        };

        var ie = new OReilly.Browser("Internet Explorer", "Microsoft", true);
        s = ie.toString() + "<br />";

        var lynx = new OReilly.Browser("Lynx", null, false);
        
    s += lynx.toString();

        document.getElementById("output").innerHTML = s;
      }
     
    </script>

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

    Note that when you run this page, the output of this code is identical to that shown in Figure4-2.

    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

    - 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 4 hosted by Hostway
    Stay green...Green IT