ASP.NET AJAX Page Methods from UserControl

I would like to utilize the ASP.NET AJAX Page Methods functionality with a user control. Is there a way to be able to specify my static [WebMethod] inside the UserControl’s code behind instead of the Page’s code behind?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You probably can’t. The user control doesn’t have all the functionality of a page and can’t be called directly. You should instead create a webservice (asmx) to handle this scenario. If you wanted, the webservice call could be routed to the static method inside your user control.

Method 2

I’ve been searching around quite a bit to find some solution to placing static WebMethods in controls. In lieu of finding a solution I had to make my own; if you’re interested in being able to do this more naturally, feel free to take a look here (or skip straight to the source ). There’s little documentation since the solution is fresh, but at the moment I’m the only person with interest in it so there’s little reason for me to get all gung-ho on it. If you get a chance and you’re interested please tell me what you think.

Method 3

The response TheXenocide gave would seem to work, but the developers state, “Control Methods for ASP.NET AJAX is provided “as is” with no guarantees or warranties express or implied, including
implied warranties of fitness for a particular purpose, merchantability, and non-infringement.”

If you are looking for a long term solution I would consider going with webservice methods. Either that or don’t use a usercontrol. You can nest an aspx page within another with an Iframe.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x