使用 jquery 调用 ascx 页面方法 [英] calling an ascx page method using jquery

查看:26
本文介绍了使用 jquery 调用 ascx 页面方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用以下语法使用 jquery 调用页面方法

I know that I can call a page method with jquery using the following syntax

$.ajax({
  type: "POST",
  url: "Default.aspx/GetDate",
  data: "{}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(msg) {
    // Replace the div's content with the page method's return.
    $("#Result").text(msg.d);
  }
});

这适用于 aspx 页面,但是否可以用于 ascx 页面?(网页控件)

This works for aspx pages but is it possible with ascx pages? (web controls)

我已经尝试了大约半个小时,因为我无法让它工作,所以我想知道它是否可能.

I've been trying it for about half an hour and since I can't get it to work I'm wondering if it's even possible.

注意:需要明确的是,当我尝试调用 ascx 页面时,我正在更新 jquery 中的 url :)

Note: Just to be clear, when I try to call the ascx page I am updating the url in jquery :)

推荐答案

否,因为 ascx 控件不代表可从客户端计算机访问的真实 URL.它们纯粹是服务器端,旨在嵌入其他页面.

No, because ascx controls don't represent a real URL that can be accessed from a client machine. They're purely server-side meant to embed in other pages.

您可能想要做的只是有一个 asx 页面,该页面提供与您当前在 ascx 文件中相同的 html 片段.aspx 页面不一定需要提供完整的 html 文档( 等),它可以只呈现您感兴趣的用户控件.

What you might want to do is just have an aspx page that provides the same snippet of html you currently have in your ascx file. An aspx page doesn't necessarily need to provide a full html document (<html><body> etc.), it can just render the user control you're interested in.

我们一直在 ingrid 插件中使用这种技术,它需要表格内容的回调 url.

We use this technique all the time with the ingrid plugin, which requires a callback url for the table contents.

这篇关于使用 jquery 调用 ascx 页面方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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