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?
- [Ajax. ajaxmethod ()]
- Public String getaddress (string userid)
- {
- String address = "";
- // Do somthing to get the address here
- Return address;
- }
[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;