FYI, I'm blogging most of my stuff over at More Wally now.
You might want to add my rss feed to your reader at:http://morewally.com/cs/blogs/wallym/rss.aspx
ASP.NET Podcast Show #11 - Intro to Ajax and the Ajax Library for .NET - Wallace B. McClure

Wallace B. McClure

All About Wally McClure - The musings of Wallym on .NET, Sql, ASP.NET, and other crazy shenanigans

News

Personal Blog

Work Blog

.NET

Book Authors

Business

Family

Friends

Georgia Tech Bloggers

Personal

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

Subscribe.

 

Download.

 

Note (Added on 9/11/2005): Check out the Interview with Michael Schwartz in Show #15.

 

Show Notes:

 

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.

 

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;

      }

 

Comments

Michael Schwarz said:

Great work!! Thanks to the intro to Ajax and my library.

CIAO
Michael
# August 15, 2005 4:31 AM

TrackBack said:

Ajax Library for .NET
# August 16, 2005 10:18 AM

Taufique said:

More Documentation & Real-Time Example needed.
# August 17, 2005 5:15 AM

Brad Wood said:

Very informative; but I've heard that atlas is quite limited.
What sounds really cool to me is AFLAX (http://tinyurl.com/94o6v). If this product works as advertised, it will be far preferable for rich content (forget Javascript).
# August 17, 2005 5:59 PM

Scott Cate - EasySearchASP.net said:

I'm wondering how anyone could think atlas is quite limited, if nothing has been released or announced about it, or has it and I missed it? Brad, what do you think is (or will be) limited about atlas? Also, what is your source?
# August 21, 2005 9:45 PM

ShauryaAnand said:

So Cool!! Great stuff.. i like the way it works...!!
# August 29, 2005 12:45 PM

Jason Gross said:

AJAX.NET offers a really nice wrapper for the basic XMLHTTP remote services. He really extends the power of it, and removes you having to define your own transported data layout/protocol. You can get to coding without having to manage how the "what is being sent" is formatted.
# September 2, 2005 6:52 AM

Nuri Kevenoglu said:

AFLAX (at least XAMLON's implemetation) is not complete yet and no one knows when it will be!... Meanwhile, AJAX has almost taken over the world! ;)
# September 6, 2005 10:47 PM

Samir Nagonnaworkhereanymo said:

Oh no!!
# September 7, 2005 7:04 PM

Weblog said:

As a follow up to our podcast on Ajax, some folks asked me about my examples. I have posted my...
# October 9, 2006 4:45 PM

raff said:

Please more examples and documentation!

Best regards

# June 22, 2007 3:19 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)