asp.net ajax.ajaxMethod

  • 2020-05-16 06:41:24
  • OfStack

Using AjaxMethod should satisfy the following points:
1. If you don't already have the ajax.dll file, download one
2. Add ajax.dll to the project reference: in VS's solution explorer, right-click on the project name -- "add project reference" -- browse to ajax.dll to confirm
3. In the webCofig < httpHandlers > add < add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/ > node
If it is IIS7, it needs to be in < system.webServer > < /system.webServer > In the add < add name="ajax" verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" / >
2: add to the CS program
protected void Page_Load(objectsender,EventArgse)
{
Ajax. Utility. RegisterTypeForAjax (typeof (ClassName)); //ClassName is the class name of the CS file
}
3: write the CS method, preceded by [Ajax.AjaxMethod ()],
If you want session to be called from AjaxMethod, write: [Ajax.AjaxMethod (HttpSessionStateRequirement.Read)],
Such as:
 
[Ajax.AjaxMethod()] 
public string GetAddress(string UserID) 
{ 
string Address=""; 
//do somthing to get the address here 
return Address; 
} 

Note that the method is written as public, otherwise it will be prompted "this property or method is not supported" when called in JS

4. Make sure it's on the page < form runat="server" > < /form > The label.

5. When called in ASPX JAVASCRIPT, add the class name, such as:
var address = ClassName.GetAddress('123').value;

Related articles: