访问ASP.NET从静态[WebMethod的(JS ajax调用)控制 [英] Access ASP.NET control from static [WebMethod] (JS ajax call)

查看:414
本文介绍了访问ASP.NET从静态[WebMethod的(JS ajax调用)控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我需要一些帮助。 我有一个ASP.NET网站和一个自定义的控制(让称之为myControl)就可以了。 我需要调用一个方法,在这种控制与AJAX。 我张贴从JavaScript(jQuery的)AJAX调用C#的WebMethod。 这工作得很好,但我不能让myControl在静态的WebMethod。 任何想法如何解决这个问题?

短版: AJAX调用从爵士到C#WebMethod的行为 - > *这里(此方法)我需要调用我的自定义的控制方法,这是因为静态方法类型不可访问*

  [WebMethod的]
公共静态列表< CustomListControl.IListItem> GetListItems()
{
    //不能得到我的控制 - 需要返回myContorl.Items;
    返回null;
}
 

解决方案

嗯,这不是正确的做法。在Web服务方法的水平,你不能看到的页面结构的任何东西。在这种方法中,你只能加载你的产品清单,并返回它。当此列表绑定到是没有GetListItems的业务。

您可以通过实现一个回调函数管理项目的显示(见<一href="http://mattberseth.com/blog/2007/06/aspnet_ajax_invoke_a_static_me.html">http://mattberseth.com/blog/2007/06/aspnet_ajax_invoke_a_static_me.html例如)或使用在UpdatePanel方法

Guys, I need some help. 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;
}

解决方案

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.

这篇关于访问ASP.NET从静态[WebMethod的(JS ajax调用)控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆