【问题标题】:ajax and user control in asp .netasp .net 中的 ajax 和用户控制
【发布时间】:2013-08-14 04:44:20
【问题描述】:

我有一个 VB .net 应用程序,其中有一个 aspx 页面(比如 default.aspx)。我正在其中加载一个用户控件(比如 usercontrol.ascx)。我需要在页面中(在 aspx 页面或 ascx 控件中)编写一个 ajax 代码应该在用户中调用一个方法(比如 test())控制。

$.ajax({
                type: 'POST',
                url: "",
                data: "{'userid':" + userId + "}",
                contentType: "application/json; charset=utf-8",
                dataType: 'json',
                success: function (data) {
                    alert(data.d);

                },
                error: function (data) {
                    alert("In error  ");
                }
            });

为了调用用户控件中的方法,我可以在这个 ajax 方法中作为 url 给出什么?

【问题讨论】:

  • 你要调用的方法在web服务或者aspx.cs页面中。

标签: asp.net ajax user-controls


【解决方案1】:

你不能在用户控件中调用 webmethod。要么你必须把你的 webmethod 放在页面中或 web 服务中。

【讨论】:

    【解决方案2】:

    传递控件名称和方法名称。

    例如:

    url: "usercontrol.ascx/test",
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-18
      • 2021-03-30
      • 1970-01-01
      • 2014-09-13
      • 1970-01-01
      相关资源
      最近更新 更多