473,804 Members | 3,353 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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);
Jun 27 '08 #1
1 2208
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);
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1772
by: darrel | last post by:
I've been playing with prototype.js and scriptaculous to create some nice drag-and-drop interaction on my applications GUI. That's working well. Now I want to take the next step and start passing data back and forth between my page and the server via AJAX. In terms of .net, can someone give me the overall concept? Normally, I'd have a function in my codebehind that grabs a dataset and then binds that to a control on my aspx page.
1
1848
by: codefragment | last post by:
Hi I have asked this on the official asp.net forums but no luck so thought I'd try here Assume you have a page with a filter control and a grid view and many other controls on it. When the filter changes you want the gridview to change but nothing else. In particular all you would like to happen is for an ajax call to occur and a new grid view to be returned.
11
16153
by: =?Utf-8?B?VHJlbnQ=?= | last post by:
I have tied an AutoCompleteExtender to a textbox to indicate suggestions to the user. Everything works fine if I utilize a webservice to fetch the results. However, I want to put the web service code into a page method. I have run the debugger only to find that the is never entered. Here are some of the things I have already tried with no success. It appears that this is a common problem. -Added the attribute to the top of the...
4
8746
by: Grant Merwitz | last post by:
Hi I am trying to implement the Microsoft Ajax.NET extensions to perform a lookup on a key press of a text box. What this will do is once a user enters a letter into the textbox, this will filter a list from a database and populate some filtered options for the user to choose in a seperate listbox. Any subsequent key presses will further filter this result set.
5
2220
by: Kursat | last post by:
Hi, I want to add new collapsable panel items using java script at client side. Is this possible to create Ajax components like collapsable panel without server round trip? Thanks in advance.
2
2215
by: =?Utf-8?B?VG9u?= | last post by:
Hello, I want to understand teh benefits of ajax technology. Does anyone has a good website where AJAX EXTENSIONS is worked out so I really understand it. There a 2 main questions: 1) How about the form load event. Why should it fire when I put a button in a update panel? Is this necessary and is only the other controls related to the update panel send back? Or the whole page (If this is true I really do not get it). But please answer...
8
2507
by: Rory Becker | last post by:
Hi All I have a need for an asp.net page to make a call to a server which it did not originate from when a button is clicked. A simple call to pass 2-3 params and return a result. I am happy to use an asynchronous model to do this. I control both servers. I have been looking at Ajax and PageMethods (Ajax.Net and Ajax Pro) and have even been looking at Calling a webservice from JS.
3
17701
by: George | last post by:
I am doing an AJAX call using JQuery on my page to which returns JSON objects and everything works fine. Now I decided to use ashx handler instead of and simply write JSON out. Then my problems begun. So here is JQuery call $.ajax({ type: 'POST', url: url,
0
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10087
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7631
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.