Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

To create Google Suggest using ASP.NET & AJAX

0.00/5 (No votes)
26 Mar 2008 1  
To create Google Suggest using ASP.NET & AJAX

Introduction

This is example of the use of simple AJAX with ASP.NET.It includes AJAX search like Google Suggest.

Background

As per new technology,the end user wants real time experience while surfing the websites.As Microsoft provides some AJAX controls with ASP.NET,But it is necessary to install AJAX control toolkit and DLL on the server.So why do such installations? This is the example of the AJAX with simple JAVASCRIPT and XMLHTTPREQUSET to implement such functionality.I have used it with ASP.NET 2.0. So we can use it for multiple use like data validation(username checking),password strength cheking,Star Rating and many more.... as per your use.

Using the code

This example has two aspx files and only on js file,that is for ajax implementation.You need to do only one thing and you example is ready to use.Just change the connection string in the process.aspx page.I have given some code snippet below:

            //AJAX.JS
            // Code snippet for AJAX requsets
            //
var me = this;

this.mRequest = null;

this.mhTarget = hTarget;

sURL=sURL+"?search="+txtVal+"&Id="+txtId+"&X="+event.screenX; 

if( window.XMLHttpRequest ) //FF,NS,OP,IE7

{

this.mRequest = new XMLHttpRequest();

}

else

if( window.ActiveXObject ) //IE5 & 6

{

this.mRequest = new ActiveXObject("Microsoft.XMLHTTP");

} 

if( this.mRequest )

{

this.mRequest.open( 'GET', sURL , true );

this.mRequest.onreadystatechange = function(){ fAJAXStateChange(me); };

this.mRequest.send( null );

}
//Function that takes result from process page and write the result in target DIV

function fAJAXStateChange( hAJAXRequest )

{

if( hAJAXRequest && hAJAXRequest.mRequest && hAJAXRequest.mRequest.readyState == 4 )

{

var s = hAJAXRequest.mRequest.responseText; 

hAJAXRequest.mhTarget.innerHTML = s; 

}

}


        

Points of Interest

I am glad to receive any modifications or new Ideas with using this code.

History

It is compatible with ASP.NET 1.1 & ASP.NET 2.0/C#

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