Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

AJAX: Exposing a server controls webmethod to the client

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
daokfella - 25 Apr 2008 22:02 GMT
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);
bruce barker - 26 Apr 2008 00:35 GMT
you server control need to inherit from Page, and you pages need to inherit
from your control.

-- bruce (sqlwork.com)

> 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
[quoted text clipped - 33 lines]
>
> window.setTimeout(test, 10000);

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.