I wrote the Ajax. Net article two days ago. Some friends asked me how to configure this stuff,CodeHow to write. Actually, quick guide.txt is clear in the example, but here I will demonstrate it step by step based on my experience. My development environment is Windows XP SP2, vs. NET 2005 beta2.
First go to The http://ajax.schwarz-interactive.de/download/AjaxSample.zip to download the demo package, or here the http://ajax.schwarz-interactive.de/download/ajax.zip directly download Ajax. dll.
1. Create a new web project in vs. NET and reference Ajax. dll.
2. modify web. config and add
<Configuration>
<System. Web>
<Httphandlers>
<Add verb = "post, get" Path = "ajax/*. ashx" type = "Ajax. pagehandlerfactory, Ajax"/>
</Httphandlers>
...
<System. Web>
</Configuration>
Httphandlers is used to dynamically generate JavaScript.
3. Create a class that implements business logic and add a method to it.
public class class1
{< br> [Ajax. ajaxmethod ()]
Public int serversideadd (INT firstnumber, int secondnumber)
{< br> return firstnumber + secondnumber;
}< BR >}< br> 4. in default. aspx. add a line to the page_load event of CS
protected void page_load (Object sender, eventargs e)
{< br> Ajax. utility. registertypeforajax (typeof (class1);
}< br> 5. in default. write the following JavaScript code in the ASPX page file
indicates calling the serversideradd function of class1,
6. Add a link to the page to trigger this function.
calculate
Well, compile and run it now. When you click the "Calculate" link on the page, do you see 5 as you wish?
All Of This Is background computing, and the browser page is not refreshed.
Postscript:
if all the steps are completed, you will find the following code in the Source Code of the generated page:
you can download and open the two scripts, Ajax. net in the end, what has been done in it, and there is such a magical function.