locked
ASP.NET AJAX Control Toolkit FAQ: Mengapa PageMethod tidak bekerja? RRS feed

  • Diskusi Umum

  • Anda dapat menambahkan metode static page ke halaman ASP.NET dan memenuhi syarat sebagai Web method. Anda kemudian dapat memanggil metode ini dari script seolah-olah mereka bagian dari layanan Web, tetapi tanpa membuat file .asmx terpisah. Untuk menciptakan Web method di halaman, impor System.Web.Services namespace dan tambahkan atribut WebMethodAttribute untuk masing-masing static page yang anda ingin ekspos.

    Untuk dapat memanggil metode static page sebagai Web method, Anda harus mengatur atribut EnablePageMethods dari kontrol ScriptManager menjadi true.

    Sebagai contoh:

    [WebMethod] 

    public static DateTime GetCurrentTime() { 

        return DateTime.UtcNow;  

    }

    Gunakan PageMethods.MethodName untuk memanggil PageMethod yang ada. 

    Sebagai contoh:

    <script language="javascript" type="text/javascript"> 

        function getCurrentTime(){ 

            PageMethods.GetCurrentTime(onSucceeded); 

        } 

        function onSucceeded(returnedValue){  

        } 

    </script>

     

    Untuk informasi lebih lanjut, silahkan buka link dibawah ini: http://asp.net/ajax/documentation/live/tutorials/ExposingWebServicesToAJAXTutorial.aspx


    Agnes Sannie [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Selasa, 29 November 2011 06.47
    Moderator