Asp.net Ajax call background static method summary

Source: Internet
Author: User
ArticleDirectory
    • 1. Ajax library Method
    • 2. jquery Method
    • 3. There is also a good example of referencing the Ajax. dll file. register the foreground method in the background. This seems to be a lot of use in. net2.0. I did not study it carefully.
Call the static method in the background from the client
1. Ajax library Method

C #Code:

 
[Webmethod] public static datetime getcurrenttime (string Str) {return datetime. Now ;}

JS Code:

<Form ID = "form1" runat = "server"> <script language = JavaScript type = "text/JavaScript"> function getcurrenttime1 () {pagemethods. getcurrenttime ('newegg Ajax training ', checkissuccess);} function checkissuccess (result) {alert (result) ;}</SCRIPT> <div> <asp: scriptmanager id = "scriptmanager1" runat = "server" enablepagemethods = "true"> </ASP: scriptmanager> <input id = "button1" type = "button" value = "client control call server method" onclick = "getcurrenttime1 () "/> </div> </form>

Note:

C # "[webmethod]" must be added to the Method

The front-end page must use the reference Server Control

<Asp: scriptmanager id = "scriptmanager1" runat = "server" enablepagemethods = "true">

</ASP: scriptmanager>

Call method: pagemethods. Name of the background method (parameter [, parameter...], name of the method called after the call is successful );

Ajax Library

2. jquery Method

C # code:

[Webmethod] public static string ABC (string ABC) {return ABC ;}

JS Code:

$ (). Ready (function () {$ ("# ajaxdemo "). click (function () {$. ajax ({type: "Post", URL: "default. aspx/ABC ", data:" {'abc': 'test'} ", contenttype:" application/JSON; charset = UTF-8 ", success: function (MSG) {alert (MSG );}})})})

Note: The jquery library file must be referenced.

3. There is also a good example of referencing the Ajax. dll file. register the foreground method in the background. This seems to be a lot of use in. net2.0. I did not study it carefully.

I also hope you can talk to each other in other simpler ways ~

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.