Click here to Skip to main content
15,907,001 members
Articles / Web Development / HTML
Article

To create Google Suggest using ASP.NET & AJAX

Rate me:
Please Sign up or sign in to vote.
1.00/5 (10 votes)
26 Mar 2008CPOL1 min read 25.6K   22   2
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Panjim,Goa
India India
Nilesh Surve
Software Engineer
Panjim,Goa
India.

Comments and Discussions

 
GeneralMy vote of 5 Pin
vishwajitg31-Oct-12 22:43
vishwajitg31-Oct-12 22:43 
GeneralSuggest works, but not with MasterPage.. Pin
motiofel17-Jul-09 1:17
motiofel17-Jul-09 1:17 

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

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