Ajax.NET Quick Start

Source: Internet
Author: User
Tags add object config datetime error handling net reference version
Ajax| Quick Start

Now the project is ready to use Ajax, ajax.net implementation, rather than Atlas, so first look at the Ajax.net,ajax.net now the latest version is AjaxPro5.11.4.2, download the address is: Www.schwarz-interactive.de

First we create a new project, the name is Ajaxpro, I use the VS2005BETA2 version .

Right-click Site name dot Add Reference add a reference to the name Ajaxpro.2.dll that we just downloaded, if you're using vs2003, add a reference to AjaxPro.dll, and then we add a Web.config file (it's depressing that vs2005 no longer automatically add Web.config Pull), modify Web.config as follows:





<add verb= "Post,get" path= "Ajaxpro/*.ashx" type= "Ajaxpro".


This means that all AJAXPRO/*.ASHX requests are handled by the ajax.pagehandlerfactory, not by the default System.Web.UI.PageHandlerFactory handler factory .

We now add a name to the Default.aspx.cs file space namespace Mydemo, here more depressing is why vs2005beta2 don't give you automatically add name space ah? and 2003 how completely different?

Now we're writing a ajaxmethod server -side approach, the only difference between him and the normal server approach is that he has to add a [Ajaxpro.ajaxmethod] to the method, and the code reads as follows:

[Ajaxpro.ajaxmethod]

Public DateTime GetServerTime ()

{

return datetime.now;

}

[Ajaxpro.ajaxmethod]

public int AddTwo (int firstint, int secondint)

{

return firstint + secondint;











At this point we also have to modify the ASPX page's <% @Page instruction line, because we have a namespace in the background, as follows: Inherits= "Mydemo._default" is to write the name space we write the client script to call the server method . There are detailed comments in the code, foreground default.aspx code:

<%@ Page language= "C #" autoeventwireup= "true"
Codefile= "Default.aspx.cs" inherits= "Mydemo._default"%>

<! DOCTYPE HTML PUBLIC "-//w3c//dtd XHTML 1.1//en"

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



<title>untitled page</title>


<body>

<form id= "Form1" runat= "Server" >

<div>

<input id= "Button1" type= "button" value= "Get server Time"

/>

<input id= "Text1" type= "text"/>

<input id= "Text2" type= "text"/>

<input id= "Button2" type= button "value=" gets two text boxes and

"/>

</div></form>

<script type= "text/javascript"

Function getservertime ()

{

//mydemo._default.getservertime () Gets the data from the server is
object, to write. Value

Alert (Mydemo._default.getservertime (). value);

}

Function Add (a,b)

{

//Convert the value of the text box to int

var a1 = parseint (a);

var B1 = parseint (b); The

//1th, 2 parameters are The parameters required by the server method, and the latter is if server returns data

/ /client to process the data of the JS function name, he has a parameter is from the server data came from

Mydemo._default.addtwo (a1,b1,getadd);

}

Function Getadd (rel)

{

//To Add. Value

Alert (rel.value);

}

</script>

</body>


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 results below, Firefox inside test through:

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;

}

}

}

    • Ajax: A new way to build Web apps
    • Discussion on the error handling mechanism of AJAX (2)
    • Discussion on the error handling mechanism of AJAX (1)
    • First experience. NET Ajax Brushless New technology
    • A brief analysis of Ajax development Technology in Rails system (4)


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.