AJAX: Exposing a server controls webmethod to the client

D

daokfella

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 EnablePageMethods() 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.MyWebMethod(successfunction, 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.MyWebMethod(successfunction, failedfunction);
}

window.setTimeout(test, 10000);
 
B

bruce barker

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

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top