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);
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);