Access to ASP.NET control from static [WebMethod] (JS ajax call)

I have an ASP.NET WebSite and a custom control (let's call it myControl). I need to call a method on this control using AJAX. I am sending an ajax call from JavaScript (jQuery) in C # WebMethod. This works fine, but I cannot get to myControl in static WebMethod. Any ideas how to solve this problem?

Short version: AJAX call from JS to C # WebMethod works → * here (in this method) I need to call a method on my custom control that is not available due to the static type of the method *

[WebMethod] public static List<CustomListControl.IListItem> GetListItems() { // CAN'T GET TO MY CONTROL - need to return myContorl.Items; return null; } 
+7
c # ajax user-controls pagemethods
source share
1 answer

Well, this is not the right approach. At the web service method level, you see nothing about the structure of the page. In this method, you can only load a list of items and return them. Where this list is linked is not GetListItems business.

You can control the display of elements by implementing a callback function (for example, http://mattberseth.com/blog/2007/06/aspnet_ajax_invoke_a_static_me.html ) or using the UpdatePanel approach.

+5
source share

All Articles