From: http://www.jm-zy.net/Notes/Article-611.html
1. Download Ajax. dll, which is available everywhere. Http://ajax.schwarz-interactive.de/CSharpSample/
2. Create a website project ajaxsample
3. decompress the downloaded aajx. DLL to the project (the directory is not limited)
4. Reference Ajax. DLL to the project.
Fifth, add the Ajax. dll section in Web. config: (the configuration must be placed in <system. Web>)
<Httphandlers>
<AddVerb= "Post, get"Path= "Ajax/*. ashx"Type= "Ajax. pagehandlerfactory, Ajax" />
</Httphandlers>
Sixth, because this is a test project, we do not consider too many architecture issues, but to separate the business and performance, we create a class file test. CSCodeIn this file. Class files are stored in the app_code directory.
Class file:
Using System;
Using System. Data;
Using System. configuration;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. webcontrols;
Using System. Web. UI. webcontrols. webparts;
Using System. Web. UI. htmlcontrols;
/// <Summary>
///Test Summary
/// </Summary>
Public Class Test
{
Public Test ()
{
//
//Todo: add the constructor logic here
//
}
[Ajax. ajaxmethod ()]
Public String Gettext ()
{
Return "This is an Ajax Test";
}
}
7. Create a new page file default. aspx and default. aspx. CS Code as follows:
Protected void page_load (Object sender, eventargs E)
{
Ajax. Utility. registertypeforajax (typeof (TEST ));
}
Default. aspx is as follows:
<% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Default. aspx. CS " Inherits = " _ Default " %>
<! Doctype HTML public " -// W3C // dtd xhtml 1.0 transitional // en " " Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< HTML xmlns = " Http://www.w3.org/1999/xhtml " >
< Head runat = " Server " >
< Title > No title page </ Title >
script language = " JavaScript " >
FunctionAjaxtest ()
{VaRA=Test. gettext (). value;
Window. Alert ();
}
</Script>
</ Head >
< Body onload = " Ajaxtest (); " >
< Form ID = " Form1 " Runat = " Server " >
</ Form >
</ Body >
</ Html >
After running, you can see the final effect.
There are several notes:
First, all functions that need to be called in Javascript need to be added to the function [Ajax. ajaxmethod ()] (For details, refer to other files)
Second, all classes of functions that are called in Javascript must be described in page_load:
Ajax. Utility. registertypeforajax (typeof (TEST ));
Test indicates the service class name.
Http://files.cnblogs.com/wangpei/ajax_dll.rar