从静态访问ASP.NET控件[WebMethod](JS ajax调用)
我有一个 ASP.NET 网站和一个自定义控件(我们称之为 myControl)。 我需要使用 AJAX 调用此控件上的方法。 我正在发布从 JavaScript (jQuery) 到 C# WebMethod 的 ajax 调用。 这工作正常,但我无法在静态 WebMethod 中访问 myControl。 有什么想法如何解决这个问题吗?
简短版本: 从 JS 到 C# WebMethod 的 AJAX 调用有效 -> * 此处(在此方法中)我需要在自定义控件上调用一个方法,该方法由于静态方法类型而无法访问 *
[WebMethod]
public static List<CustomListControl.IListItem> GetListItems()
{
// CAN'T GET TO MY CONTROL - need to return myContorl.Items;
return null;
}
I have a ASP.NET WebSite and a custom control (lets call it myControl) on it.
I need to call a method on this control with AJAX.
I'm posting ajax call from JavaScript (jQuery) to C# WebMethod.
This works fine, but I can't get to myControl in a 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 which is inaccessible because of static method type *
[WebMethod]
public static List<CustomListControl.IListItem> GetListItems()
{
// CAN'T GET TO MY CONTROL - need to return myContorl.Items;
return null;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,这不是正确的方法。在 Web 服务方法级别,您看不到任何有关页面结构的信息。在此方法中,您只能加载项目列表并将其返回。此列表绑定到何处与 GetListItems 无关。
您可以通过实现回调函数来管理项目的显示(请参阅 http://mattberseth。例如,com/blog/2007/06/aspnet_ajax_invoke_a_static_me.html)或使用 UpdatePanel 方法。
Well, that's not the correct approach. At the web service method level you cannot see anything about the page structure. In this method you can only load your list of items and return it. Where this list is binded to is none of GetListItems' business.
You can manage the display of the Items by implementing a callback function (see http://mattberseth.com/blog/2007/06/aspnet_ajax_invoke_a_static_me.html for example) or by using the UpdatePanel approach.