How to use ASP. Ajaxmethod

Source: Internet
Author: User

Using Ajaxmethod, you can asynchronously invoke the server-side method on the client, simply by invoking the method in the background. cs file in JS.

Do some things that JS can't do, such as querying the database

Use Ajaxmethod to meet a few points:

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

2. Add Ajax.dll to the project reference: right-click the project name in the VS Solution Explorer--"Add Project reference

"--Browse, find Ajax.dll OK

3. Webcofig

Type= "ajax.pagehandlerfactory, Ajax"/> Node

If it is IIS7, you need to add <add to the Handlers node in the <system.webServer></system.webServer>

Name= "Ajax" verb= "Post,get" path= "Ajax/*.ashx" type= "Ajax.pagehandlerfactory, Ajax"/>

2: Add in CS program

protected void Page_Load (OBJECTSENDER,EVENTARGSE)

{

Ajax.Utility.RegisterTypeForAjax (typeof (ClassName));//classname is the class name of this CS file

}

3: Write the CS method, the method is preceded by [Ajax.ajaxmethod ()],

If you want to make Ajaxmethod inside can call session, write: [Ajax.ajaxmethod

(Httpsessionstaterequirement.read)],

Such as:

Copy Code

The code is as follows:

[Ajax.ajaxmethod ()]

public string getaddress (string UserID)

{

String Address= "";

Do somthing to get the address here

return Address;

}

Note that the method should be written as public, or it will be called in JS to "do not support this property or method"

4. Make sure the page has <form runat= "server" ></form> tags.

5. Added class name when called in aspx JavaScript

Original source: http://www.ynpxrz.com/n710705c2023.aspx

How to use ASP. Ajaxmethod

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.