How to Use Ajax. ajaxmethod

Source: Internet
Author: User
How to Use Ajax. ajaxmethod classification: extjs + C # + LINQ 2010-07-15 667 people read comments (3) collect reports

The ajaxmethod can be used to asynchronously call the server method on the client. Simply put, the method in the background. CS file is called in JS to perform operations that cannot be done by JS, such as querying the database. The following requirements must be met when using ajaxmethod:

1. If no Ajax. dll file exists, download one first.

2. Add Ajax. DLL to project reference: In Solution Explorer of Vs, right-click the project name, click "add project reference", and Click Browse. Find Ajax. DLL to confirm.

3. <Httphandlers> and <add verb = "post, get" Path = "ajax/*. ashx" type = "Ajax. pagehandlerfactory, Ajax"/> nodes in webcofig

For iis7. webserver> </system. add <Add name = "ajax" verb = "post, get" Path = "ajax/* To webserver> /*. ashx "type =" Ajax. pagehandlerfactory, Ajax "/>
2: add
Protected void page_load (objectsender, eventargse)
{
Ajax. Utility. registertypeforajax (typeof (classname); // classname is the class name of this CS File
}
3: Compile the Cs method. Add [Ajax. ajaxmethod ()] before the method.

To enable the ajaxmethod to call the session, write it as [Ajax. ajaxmethod (httpsessionstaterequirement. Read)],

For example:

View plaincopy to clipboardprint?

  1. [Ajax. ajaxmethod ()]
  2. Public String getaddress (string userid)
  3. {
  4. String address = "";
  5. // Do somthing to get the address here
  6. Return address;
  7. }

[Ajax. ajaxmethod ()] <br/> Public String getaddress (string userid) <br/>{< br/> string address = ""; <br/> // do somthing to get the address here <br/> return address; <br/>}

 

Note that the method should be written as public. Otherwise, the system will prompt "This attribute or method is not supported" when calling in Js"

4. Make sure the page contains the <form runat = "server"> </form> label.

5. Add the class name when calling aspx JavaScript, for example:

VaR address = classname. getaddress ('20140901'). 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.