Ajax. Net Quick Start

Source: Internet
Author: User

Now the project is ready to use ajax, with ajax.net implementation, rather than atlas, so first look at ajax.net, Ajax. Net now the latest version is AjaxPro5.11.4.2, is: www.schwarz-interactive.de

First, create a new project named AjaxPro. I use vs2005beta2.

Right-click the site name and click add reference to add a reference to the AjaxPro.2.dll we just downloaded. If vs2003 is used, add the reference to AjaxPro. dll reference, and then we add a web. the config file is depressing because vs2005 does not automatically add web. config file), modify the web. config:

      
      


This means that all ajaxpro/*. ashx requests are handled by Ajax. PageHandlerFactory, rather than by the default System. Web. UI. PageHandlerFactory handler factory.

Now we can add a namespace MyDemo to the Default. aspx. cs file. What is even more depressing here is why does vs2005beta2 not automatically add a namespace to you? How is it totally different from 2003?

Now let's write an AjaxMethod server method. The only difference between it and the common server method is that it must add a [AjaxPro. AjaxMethod] on the method. The Code is as follows:

[AjaxPro. AjaxMethod]
Public DateTime GetServerTime ()
{
Return DateTime. Now;
}
[AjaxPro. AjaxMethod]
Public int AddTwo (int firstInt, int secondInt)
{
Return firstInt + secondInt;
}
We must register this class in Page_Load as follows:
Protected void Page_Load (object sender, EventArgs e)
{
AjaxPro. Utility. RegisterTypeForAjax (typeof (_ Default ));
}

At this time, we must modify the <% @ Page command line of the aspx Page, because we have a namespace in the background, as shown below: Inherits = "MyDemo. _ Default "is to write the namespace. We will then write the client script to call the server method. The Code contains detailed annotations. The front-end Default. aspx code:

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile = "Default. aspx. cs" Inherits = "MyDemo. _ Default" %>

Http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd>



Untitled Page






Background Default. aspx. cs code:

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;
Namespace MyDemo
{
Public partial class _ Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
AjaxPro. Utility. RegisterTypeForAjax (typeof (_ Default ));
}

[AjaxPro. AjaxMethod]
Public DateTime GetServerTime ()
{
Return DateTime. Now;
}
[AjaxPro. AjaxMethod]
Public int AddTwo (int firstInt, int secondInt)
{
Return firstInt + secondInt;
}
}
}

Press F5 to run the result as follows, and the test passes in firefox:

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;
namespace MyDemo
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));
}

[AjaxPro.AjaxMethod]
public DateTime GetServerTime()
{
return DateTime.Now;
}
[AjaxPro.AjaxMethod]
public int AddTwo(int firstInt, int secondInt)
{
return firstInt + secondInt;
}
}
}

(

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.