从静态访问ASP.NET控件[WebMethod](JS ajax调用)

发布于 2024-08-19 14:24:02 字数 487 浏览 9 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放赐 2024-08-26 14:24:02

嗯,这不是正确的方法。在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文