ASP.NET
  Home arrow ASP.NET arrow Page 2 - Finishing an ASP.NET AJAX-based Applicatio...
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

Finishing an ASP.NET AJAX-based Application
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 4
    2007-07-23

    Table of Contents:
  • Finishing an ASP.NET AJAX-based Application
  • Authoring the Web Service to Supply with Data
  • Adding the CascadingDropDown Control to the Web Page
  • Modifying the Related Contents in the CodeFile

  • 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


    Finishing an ASP.NET AJAX-based Application - Authoring the Web Service to Supply with Data


    (Page 2 of 4 )

    Right click the project and choose "Add new item" to create a new Web Service named LocationService.asmx. Next, we will open the LocationService.cs file and create the required web methods.

    First, as required by the framework, we must put the ScriptService attribute before the Web Service so that the MS AJAX JavaScript framework will call it correctly:

     

    [System.Web.Script.Services.ScriptService]

     

    Now, let's first define a Web Method named GetCountries, through which we can get the list of countries from DropDownList control named ddlCountry:

     

    [WebMethod]

    public CascadingDropDownNameValue[] GetCountries(string knownCategoryValues, string category)

    {

       List<CascadingDropDownNameValue> countryList = new List<CascadingDropDownNameValue>();

     

       DataSet dsCountry = Country.GetCountries();

       foreach (DataRow row in dsCountry.Tables[0].Rows)

       {

         countryList.Add(new CascadingDropDownNameValue(row["CountryName"].ToString(), row["CountryID"].ToString()));

       }

     

       return countryList.ToArray();

    }

     

    Note that in this method we invoke the Country.GetCountries() method to get all the related countries' information and use it to populate a list named "countryList."

    Next, define another Web Method -- GetStatesForCountry -- through which we can get the list of states for the DropDownList named "ddlState" according to the item selected from the first DropDownList control, named ddlCountry:

     

    [WebMethod]

    public CascadingDropDownNameValue[] GetStatesForCountry(string knownCategoryValues, string category)

    {

       StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

       List<CascadingDropDownNameValue> stateList = new List<CascadingDropDownNameValue>();

       DataSet dsState = State.GetStates(int.Parse(kv["Country"]));

       foreach (DataRow row in dsState.Tables[0].Rows)

       {

         stateList.Add(new CascadingDropDownNameValue(row["StateName"].ToString(), row["StateID"].ToString()));

       }

       return stateList.ToArray();

    }

     

    First, the knownCategoryValues parameter which represents the selected content from the DropDownList ddlCountry is passed into this web method. Second, we resolve this parameter into a StringDictionary object. Third, we get the information about the states associated with the specified country by calling the  State.GetStates() method. Finally, an array of the states list is returned.

    More ASP.NET Articles
    More By Xianzhong Zhu


       · I was looking for this since long time. Finally I find it. Great work. I am working...
     

    ASP.NET ARTICLES

    - 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
    - Building a Simple Storefront with LINQ





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