Click here to Skip to main content
Licence 
First Posted 28 Mar 2006
Views 16,106
Bookmarked 25 times

Simple use of Ajax

By | 28 Mar 2006 | Article
Simple use of Ajax technology in .net

Sample screenshot

Introduction

This article is introducing the usage of ajax technology by implementing a simple web page using the Ajax.dll made shwartz.

 

1)Make your application.
2)Make your database:

   table name(buildings) columns(BuildingID,Price,Area,Address,Image)


3) Add reference to Ajax.dll.
4) Design your class that contains the business logic for your web page.

[Ajax.AjaxMethod()]

public DataSet GetBuildings()

{

ds=db.MySelect("select * from buildings");

return ds;

}

[Ajax.AjaxMethod()]

public DataSet Search(string price,string priceCondition,string area,string areaCondition)

{

string sqlSearch="select * from buildings where 1=1";

if(price!="")

sqlSearch+=" and price"+priceCondition+""+price+"";

if(area!="")

sqlSearch+=" and area"+areaCondition+""+area+"";

ds=db.MySelect(sqlSearch);

return ds;

}


5) Add attribute [Ajax.AjaxMethod()] on every method that will be called by java script.

6)Add to the page load, note that you get the type of the class you made.

Ajax.Utility.RegisterTypeForAjax(typeof(ClassSearch));


7) In aspx make 2 functions: first that will call the server side method, second will be its callback.

//2 functions for getting all the buildings

function GetBuildings()

{

    ClassSearch.GetBuildings(GetBuildings_callBack);

}

function GetBuildings_callBack(response)</code>


  {
       var ds=response.value;
       if(ds!=null && typeof(ds)=="object" && ds.Tables!=null)
       {
           var myDS=new Array();
           myDS[myDS.length]="<table border=1 id=tblData><tr><td                                  style=\"VISIBILITY: hidden\">BuildingID</td><td>Price</td><td>Area</td><td>Address</td><td>Image</td></tr>";
    for(var i=0;i<ds.Tables[0].Rows.length;i++)
    {
     myDS[myDS.length]="<tr>";
     myDS[myDS.length]="<td style=\"VISIBILITY: hidden\">"+ds.Tables[0].Rows[i].BuildingID+"</td>";
     myDS[myDS.length]="<td>"+ds.Tables[0].Rows[i].Price+"</td>";
     myDS[myDS.length]="<td>"+ds.Tables[0].Rows[i].Area+"</td>";
     myDS[myDS.length]="<td>"+ds.Tables[0].Rows[i].Address+"</td>";
     myDS[myDS.length]="<td><img height=30 width=30 src='"+ds.Tables[0].Rows[i].Image+"'></td>";
     myDS[myDS.length]="<td><input type=button onclick=\"window.navigate('Buildings.aspx?bid="+ds.Tables[0].Rows[i].BuildingID+"');\"     value='More                         Info'</td>";
          myDS[myDS.length]="</tr>";     
        }
        myDS[myDS.length]="</table>";
        document.getElementById("lblData").innerHTML=myDS.join("");
     }
     else
     {
        alert("Error. [3001] " + response.request.responseText);
     }
  }


8) loop through the returned data.

9) Add this to the web.config:

<httpHandlers><add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/></httpHandlers>


 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

realhossam

Web Developer

Egypt Egypt

Member

Asp.net Developer since 2004.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generaldownload has many errors Pinmemberoverred2:49 28 Mar '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 28 Mar 2006
Article Copyright 2006 by realhossam
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid