• Home
  • New Entries
  • Popular Entries
  • Submit a Story
  • About

ASP.NET Podcast Show sharp 11 - Intro to Ajax and the Ajax Library for .NET ...

Before looking at the code samples, understand that the client ids may not be 100% accurate in all situations. It is best to use the ClientId property of the necessary controls to get the appropriate property name.

View More Info

Code Sample (basic Ajax)

Client Site Code:

function sState2_onchange() {

    var iStateIndex = document.forms[0].sState2.selectedIndex;

    var sValue = document.forms[0].sState2[iStateIndex].value;

    AjaxFunctions.GetCityRecords(sValue, GetCityRecords_CallBack);

}

 

function GetCityRecords_CallBack(response){

    var ds = response.value;

    var i = 0;

    var iLength = 0;

    if (response.error != null){

        alert(response.error);

        return;

    }

 

    if ((ds.Tables != null) && (ds.Tables[0].Rows.length > 0))

    {

        iLength = document.getElementById("sCity2").options.length;

        document.getElementById("sCity2").visible = true;

        for(i=0; i<iLength; i++)

        {

            document.getElementById("sCity2").options[0] = null;

        }

      

        for(i=0; i<ds.Tables[0].Rows.length; i++)

        {

            document.getElementById("sCity2").options.add(new Option(ds.Tables[0].Rows[i]["City"],ds.Tables[0].Rows[i]["tblCityId"]))

        }

    }

    else

    {

        alert("Error: " + response.request.responseText);

        document.getElementById("sState2").visible = false;

    }

          

 

}

 

Server Side Code:

      [Ajax.AjaxMethod()]

      public System.Data.DataSet GetCityRecords(int iState)

      {

            int i = 0;

            DataSet ds = new DataSet();

            DataTable dt = new DataTable();

            DataRow dr;

            dt.Columns.Add(new DataColumn("tblCityId", System.Type.GetType("System.Int32")));

            dt.Columns.Add(new DataColumn("City", System.Type.GetType("System.String")));

            if (iState == 1)

            {

                  dr = dt.NewRow();

                  dr["tblCityId"] = 1;

                  dr["City"] = "Knoxville";

                  dt.Rows.Add(dr);

                  dr = dt.NewRow();

                  dr["tblCityId"] = 2;

                  dr["City"] = "Nashville";

                  dt.Rows.Add(dr);

                  ds.Tables.Add(dt);

            }

            return (ds);

      }

 

 

Code Sample (html control from server)

Client Side Code:

function sState3_onchange(stateid){

    HtmlControlUpdate(AjaxFunctions.ReturnCitys, City3Display, stateid);

}

 

Server Side Code:

      [Ajax.AjaxMethod()]

      public System.Web.UI.HtmlControls.HtmlSelect ReturnCitys(string State)

      {

            System.Web.UI.HtmlControls.HtmlSelect ctrl = new System.Web.UI.HtmlControls.HtmlSelect();

            ctrl.ID = "sCity3";

            ctrl.Attributes.Add("onchange", "alert(hi);");

            if (State == "1")

            {

                  ctrl.Items.Add(String.Empty);

                  ctrl.Items.Add(new ListItem("Knoxville", "1"));

                  ctrl.Items.Add(new ListItem("Nashville", "2"));

            }

            return ctrl;

      }
source: weblogs

 View Full Story.
Posted at 09:55:58 am | Permalink | Posted in .Net  

Related Stuff

  • MooV: Using cutting edge Video phones and Software Video Phones - coupling all that with VoIP and empowering the disabled.

  • Moo Telecom: VoIP communications made easy - Ring anyway with the fun and ease of using a normal phone

  • TagR:Mobile Social Network with Real Time Locations Based services, and Ambience Intelligence, VoiP, IM, Skype, Googletalk, Mapping, Flickr, Events, Calendaring, Scheduling, SecondLife Support

  • ClearSMS : ClearSMS is a Web-based application that lets you send bulk SMS messages to your customers, contacts, or just about anyone.

  • Jajah:jah is a VoIP (Voice over IP) provider, founded by Austrians Roman Scharf and Daniel Mattes in 2005[1]. The Jajah headquarters are located in Mountain View, CA, USA, and Luxembourg. Jajah maintains a development centre in Israel.

  • Skype: It’s free to download and free to call other people on Skype. Skype the number one voice over ip software

  • PrivatePhone: a free local phone number with voicemail and messages you can check online or from any phone.

Be the first ... |Add your comment.

Your Comment ...

  Name (required)

  Email (required, hidden)

  Website


About Ajaxlines

Ajaxlines is a project focused on providing its audience with a database of most of Ajax related articles, resources, tutorials and services from around the world.

Its purpose is to showcase the power of Ajax and to act as a portal to the Ajax development community.


Recent Stuff

ASP.NET MVC & Threads

How to add Google Maps to your website

Speeding Up Post Load Script

Simple AJAX Methodology

Javascript Ajax Class

Threading in JavaScript


Our Partners

Ajax Projects

Web 2.0 Sites

Webloglines

Human Development Handbook

Software Development Company

Ajaxlines


Search


Topics

  • .Net (98)
  • Articles (78)
  • Bookmarking (35)
  • Calendar (18)
  • Chat (38)
  • ColdFusion (3)
  • CSS (33)
  • Email (23)
  • Flash (13)
  • Games (6)
  • Google (22)
  • Html (10)
  • Image (11)
  • International Calls & VOIP (7)
  • Java (35)
  • Javascript (156)
  • JSON (19)
  • Perl (2)
  • PHP (83)
  • Presentation (19)
  • Python (3)
  • Resources (2)
  • RSS (1)
  • Ruby (7)
  • Storage (4)
  • Toolkits (90)
  • Tutorials (193)
  • UI (11)
  • Utilities (162)
  • Web2.0 (13)
  • XmlHttpRequest (19)
  • YUI (4)

© 2006 www.ajaxlines.com. All Rights Reserved. Powered by IRange