Ajax.ajaxmethod Use detailed

Source: Internet
Author: User

Using Ajaxmethod can asynchronously invoke the server-side method in the client, simply call the background in JS. cs file in the method, do some JS can not do the operation, such as query the database. Use Ajaxmethod to satisfy a few points:

1. If you don't have a ajax.dll file, download the first one to

2. To add Ajax.dll to a project reference: Right-click the project name-"Add Project Reference" in the VS Solution Explorer-Browse, find Ajax.dll OK

3. Webcofig

If it is IIS7, you need to add <add name= "ajax" verb= "Post,get path=" ajax/* in <system.webServer></system.webServer>. Ashx "Type=" ajax.pagehandlerfactory, Ajax "/>
2: In the CS program plus
protected void Page_Load (OBJECTSENDER,EVENTARGSE)
{
Ajax.Utility.RegisterTypeForAjax (typeof (ClassName));//classname is the class name of this CS file
}
3: Write Cs method, the method preceded by [Ajax.ajaxmethod ()],

If you want to make the Ajaxmethod inside can call session, write: [Ajax.ajaxmethod (Httpsessionstaterequirement.read)],

Such as:

[Ajax.ajaxmethod ()]

The code is as follows Copy Code
public string getaddress (string UserID)
{
String Address= "";
Do somthing to get this address
return address;
}

Note that the method should be written public, otherwise the call in JS will be prompted "Do not support this property or method"


4. Make sure that there are <form runat= "server" ></form> labels on the page.


5. aspx in JavaScript when called with the class name, such as:

var address = classname.getaddress (' 123 '). Value;

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.