AJAX: Exposing a server controls webmethod to the client

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • daokfella

    AJAX: Exposing a server controls webmethod to the client

    I have a Webmethod in a server control which needs to be called using
    AJAX. The control writes a javascript block that uses setTimeout to
    call a an ajax js function after 10 seconds.

    When developing (not using a server control) on an aspx page, this
    worked great. I set the EnablePageMetho ds() to true on the
    ScriptManager. The method was marked as WebMethod in the page class.
    Thus, I could call the ajax method like this:
    PageMethods.MyW ebMethod(succes sfunction, failedfunction) .

    Now I'm trying to strip out the code into a server control so it can
    be used on a page-by-page basis. The only thing I can't figure out is
    how to expose the webmethod (now in a server control) so it can be
    prototyped and called in an ajax script.

    Is there an easy way to register the server control's webmethod with
    the page so I can call it via ajax?


    -----------------------------
    Here is my code as it was in my page:

    function successfunction (returnVal, context) {
    ...
    }

    function failedfunction( ) {
    ...
    }

    function test() {

    // WHAT DO I NEED TO DO TO EXPOSE MYWEBMETHOD FROM A SERVER
    CONTROL?
    PageMethods.MyW ebMethod(succes sfunction, failedfunction) ;
    }

    window.setTimeo ut(test, 10000);
  • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

    #2
    RE: AJAX: Exposing a server controls webmethod to the client

    you server control need to inherit from Page, and you pages need to inherit
    from your control.

    -- bruce (sqlwork.com)


    "daokfella" wrote:
    I have a Webmethod in a server control which needs to be called using
    AJAX. The control writes a javascript block that uses setTimeout to
    call a an ajax js function after 10 seconds.
    >
    When developing (not using a server control) on an aspx page, this
    worked great. I set the EnablePageMetho ds() to true on the
    ScriptManager. The method was marked as WebMethod in the page class.
    Thus, I could call the ajax method like this:
    PageMethods.MyW ebMethod(succes sfunction, failedfunction) .
    >
    Now I'm trying to strip out the code into a server control so it can
    be used on a page-by-page basis. The only thing I can't figure out is
    how to expose the webmethod (now in a server control) so it can be
    prototyped and called in an ajax script.
    >
    Is there an easy way to register the server control's webmethod with
    the page so I can call it via ajax?
    >
    >
    -----------------------------
    Here is my code as it was in my page:
    >
    function successfunction (returnVal, context) {
    ...
    }
    >
    function failedfunction( ) {
    ...
    }
    >
    function test() {
    >
    // WHAT DO I NEED TO DO TO EXPOSE MYWEBMETHOD FROM A SERVER
    CONTROL?
    PageMethods.MyW ebMethod(succes sfunction, failedfunction) ;
    }
    >
    window.setTimeo ut(test, 10000);
    >

    Comment

    Working...