The Ajaxpro framework uses collation (a) A simple asynchronous interactive page __ajax

Source: Internet
Author: User
1. First introduce ajaxpro.2.dll into the project
2. Add the following nodes in the Web.config file <system.web> node < httphandlers >
< add verb = "*" Path = "*.ashx" type = "Ajaxpro.ajaxhandlerfactory,ajaxpro.2"/>
Server-side page code public partial class _default:system.web.ui.page
... {
protected void Page_Load (object sender, EventArgs e)
... {
Registering AJAX Classes
AjaxPro.Utility.RegisterTypeForAjax (typeof (_default));
}


[Ajaxpro.ajaxmethod]//Duanfang Add (Ajaxmethod) attribute to the server to be invoked
public string Welcome (string name)
... {
Return "Hello" + name;
}
Client code: <% ... @ 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 > Welcome </title >
< script type = "Text/javascript" > ...
function Callservermethod ()
... {
Get the value in the text box
var Name=document.getelementbyid ("Text1"). Value;
Call the server-side method and indicate the handler function
_default.welcome (Name,callback);
}

Function callback (RES)
... {
The Div object that gets the display information
var Odiv=document.getelementbyid ("Welcomemsg");
Specify the text returned from the server for the innerHTML property of the Div object
Odiv.innerhtml=res.value;
}
</script >
< BODY >
< form ID = "Form1" runat = "server" >
< div >
< input ID = "TEXT1" type = "Text"/>
< input ID = "Button1" type = "button" value = "OK" onclick = "callservermethod ();"/></div >
< div id = "welcomemsg" ></div >
</form >
</Body >
</HTML >

Such a simple AJAX application is done.

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.