使用jQuery AJAX调用,而不是页面$ C $控制$ C $ ASP.NET功能的c-背后C-背后 [英] Using jQuery AJAX to call ASP.NET function in control code-behind instead of page code-behind

查看:120
本文介绍了使用jQuery AJAX调用,而不是页面$ C $控制$ C $ ASP.NET功能的c-背后C-背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我创建一个使用一些AJAX在jQuery的用户控件。

I have a user control that I'm creating that is using some AJAX in jQuery.

我需要调用我的控制code-后面的功能,但每一个例子,我在网上找到的是这样的:

I need to call a function in the code-behind of my control, but every example I find online looks like this:

$("input").click(function() {
    $.ajax({
        type: "POST",
        url: "Default.aspx/GetResult",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(result) {
            //do something
        }
    });
});

这工作正常,如果我在Default.aspx页面的方法。但我不希望具备的功能有,我需要在我的控制的code隐藏的功能。如何修改url属性来调用正确的函数?

This works fine if I have the method in the Default.aspx page. But I don't want to have the function there, I need the function in the code-behind of my control. How can I modify the url property to call the correct function?

我想:

url: "GetResult"

但没有奏效。

but that didn't work.

推荐答案

您不能... 的WebMethods 必须在Web服务或网页,他们不能在里面用户控件。

You can't...WebMethods have to be in WebServices or Pages, they cannot be inside UserControls.

想想看,用不同的方式看​​问题更清楚一点......什么URL到用户控件?由于没有办法来访问他们,你不能在方法直接。你可以在你的网页尝试另一种方式也许是,也许一个代理方法?

Think about it a different way to see the issue a bit clearer...what's the URL to a UserControl? Since there's no way to access them you can't get at the method directly. You could try another way perhaps, maybe a proxy method in your page?

这篇关于使用jQuery AJAX调用,而不是页面$ C $控制$ C $ ASP.NET功能的c-背后C-背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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