Click here to Skip to main content
Licence CPOL
First Posted 26 Mar 2008
Views 10,908
Downloads 91
Bookmarked 21 times

To create Google Suggest using ASP.NET & AJAX

By | 26 Mar 2008 | Article
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)

About the Author

Nilesh Surve

Software Developer (Senior)
Panjim,Goa
India India

Member

Nilesh Surve
Software Engineer
Panjim,Goa
India.

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
GeneralSuggest works, but not with MasterPage.. Pinmembermotiofel1:17 17 Jul '09  

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 27 Mar 2008
Article Copyright 2008 by Nilesh Surve
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid