Use of Microsoft ajax library of ES2en.ajaxMethod

  • 2020-06-23 00:12:02
  • OfStack

With ajax.ajaxMethod, you need to do four things

1: webCofig < httpHandlers > add < add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/ > contact

2: Add to CS program


protected void Page_Load(object sender, EventArgs e)
    {
        Ajax.Utility.RegisterTypeForAjax(typeof(NewsDrop));//NewsDrop Is this CS The class name of the file 
    }

3: Before the method [Ajax. AjaxMethod()]

[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]

4: Call in JAVASCRIPT of ASPX with the class name

AjaxMethod can be used to asynchronously invoke server-side methods on the client side, which simply means to invoke the methods in the background.cs file in JS to do some operations that JS cannot do, such as querying the database. To use AjaxMethod, the following points should be met:

1. If you don't already have an ES38en.dll file, download one

2. Add ES42en.dll to project reference: In VS's Solution Explorer, right-click the project name -- "Add Project Reference" -- browse to ajax.dll ok

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 CS program


protected void Page_Load(objectsender,EventArgse)
{
     Ajax.Utility.RegisterTypeForAjax(typeof(ClassName));//ClassName Is this CS The class name of the file 
}

3: Prepare CS method and add [Ajax. AjaxMethod()] before the method,

To make AjaxMethod call session, 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 should be written as public, otherwise it will be prompted "This property or method is not supported" when invoked in JS

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

5. ASPX JAVASCRIPT is called with the class name, such as:

var address = ClassName.GetAddress('123').value;


Related articles: