Ajax. Net entry level

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.