.NET
  Home arrow .NET arrow Coding an AjaxPro.NET Based Search Engine ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

Coding an AjaxPro.NET Based Search Engine for Your Website
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2007-10-23

    Table of Contents:
  • Coding an AjaxPro.NET Based Search Engine for Your Website
  • The Client-side Design
  • Optimization
  • Finishing Up

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Coding an AjaxPro.NET Based Search Engine for Your Website


    (Page 1 of 4 )

    In yesterday's article, we began building a search engine with AJAX functionality to be embedded into a .NET-based web site. We set up the frameworks we planned to use and designed the database. In this part, the conclusion to the tutorial, we will get into the client- and server-side design, add a couple of optimizations to the code, and then test out our new search engine.
    A downloadable .rar file is available for this article.

    The Server-side Design

    Before putting the AjaxPro.NET framework into our application, we should get everything ready. Above all, we should add a reference to AjaxPro.2.dll to the project, which will result in generating a Bin folder. With this done, we will also have to modify the relevant part in the configure file-Web.config, as show in the following code snippet:


    //......(omitted)

    <system.web>

      <httpHandlers>

    <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,
    AjaxPro" />

      </httpHandlers>

    ......(omitted)

    </system.web>;


    Moreover, we should do something inside the "Search.aspx.cs" code file to register the current page class as the following:


    [AjaxPro.AjaxNamespace("MySearchEngine")]

      public partial class Search : System.Web.UI.Page{

       private void Page_Load(object sender, System.EventArgs e){

        Utility.RegisterTypeForAjax(typeof(Search));

    }


    Note the first line of code is quite different from that provided by early versions of the framework. Be careful!

    With the above steps prepared, we can now write the Ajax methods. Let's focus on the first one, GetResultXml:


    [AjaxPro.AjaxMethod]

      public string GetResultXml(string strWord){

    string strConnection = ConfigurationManager.ConnectionStrings
    ["MyConnectionString"].ConnectionString;

      SqlConnection conn = new SqlConnection(strConnection);

       SqlCommand cmd = conn.CreateCommand();

      cmd.CommandText = string.Format(

    "SELECT id, title, author FROM Article WHERE title LIKE '%{0}%'",strWord );

      DataSet ds = new DataSet("ArticleDataSet");

       SqlDataAdapter da = new SqlDataAdapter(cmd);

    try{

      da.Fill(ds);

    }

      catch (SqlException) {}

    finally{

      conn.Close();

    }

      return ds.GetXml();

    }


    First, according to the downloaded materials, we have to put the attribute [AjaxPro.AjaxMethod] before every method that will be called via the AjaxPro.NET framework from the client side. The several steps that follow are the typical ASP.NET 2.0 database operation. The first point to notice is that we name the DataSet object "ArticleDataSet," so that will be conveniently used later. In the last step, we convert the record data in table form into a XML string by calling the GetXml method of our created DataSet instance.

    Now let's turn our attention to the next Ajax method, namely GetXsl:


    [AjaxPro.AjaxMethod]

      public string GetXsl(){

       XmlDocument doc = new XmlDocument();

      string strPath = Server.MapPath("../xsl/trans.xslt");

       doc.Load(strPath);

        return doc.InnerXml;

    }


    This method is relatively simple; its working relies on the XmlDocument class. We first get and load the required .xslt file, "trans.xslt," into the doc object. Then we directly return the XML-formatted string by returning the value of the InnerXml property of the doc object.

    There is one final Ajax method: GetResultCount, which is responsible for returning the total number of the articles that satisfy the searching condition. Since it is also pretty simple, we will not dwell on it; please refer to the downloadable source code included at the beginning of this article.

    More .NET Articles
    More By Xianzhong Zhu


     

    .NET ARTICLES

    - Building Applications with Windows Workflow ...
    - Building the Data and Business Layers Using ...
    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC
    - The Windows Ribbon Framework
    - Markup Language for the Ribbon Framework
    - Visually Upgrade Your MFC Project
    - New Features for the Statusbar in MFC
    - Working with the Statusbar in MFC
    - Iron Speed Design v60 Review
    - Binary and XML Serialization
    - Using CrystalReportViewer to Display Crystal...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek