从 JavaScript 调用 ASP.NET 代码隐藏方法

发布于 2024-11-02 05:46:11 字数 62 浏览 5 评论 0原文

有人可以告诉我如何从客户端 JavaScript 调用 ASP.NET 代码隐藏方法吗?

谢谢

Can someone please tell me how I can invoke a ASP.NET codebehind method from client-side JavaScript?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

绝不服输 2024-11-09 05:46:11

这是一篇关于如何对代码隐藏方法进行 Ajax 调用的非常好的文章:使用jQuery直接调用ASP.NET AJAX页面方法

Here's a very good article on how to do an Ajax call to a code-behind method: Using jQuery to directly call ASP.NET AJAX page methods

笔落惊风雨 2024-11-09 05:46:11

我一直使用页面方法。他们都很好。

您可以阅读 Dave 的博客文章,了解分步教程:

I've always used Page Methods. They are pretty good.

You can read the blogpost by Dave for step by step tutorial: http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/

挽容 2024-11-09 05:46:11

使用更新面板控件是最简单的方法,但您可以将页面发布到服务器并使用 Sys.Net.WebRequest 获取结果:http://msdn.microsoft.com/en-us/library/bb310979.aspx

这要困难得多,因为您必须手动更新页面中的响应,清除旧内容,解析结果并注入新内容。完成此操作的典型方法是使用 Web 服务并调用 Sys.Net.WebServiceProxy.invoke 方法: http://msdn.microsoft.com/en-us/library/bb383814.aspx。这可以调用页面内的 Web 服务(页面方法)或单独的 ASMX 或 WCF Web 服务。

HTH。

Use an update panel control is the easiest way, but you can post the page to the server and get the result using Sys.Net.WebRequest: http://msdn.microsoft.com/en-us/library/bb310979.aspx.

That's a lot harder because you have to manually update the response in the page, wipe out the old content, parse the result, and inject the new content. The typical way it is done is to use a web service and call Sys.Net.WebServiceProxy.invoke method: http://msdn.microsoft.com/en-us/library/bb383814.aspx. This can call a web service within the page (page methods) or a separate ASMX or WCF web service.

HTH.

無處可尋 2024-11-09 05:46:11

使用 jQuery AJAX
这是一个很好的来源

$.ajax({
  type: "POST",
  url: "MessagePopup.asmx/SendMessage",
  data: "{subject:'" + subject + "',message:'" + message + ",messageId:'" + messageId + "',pupilId:'" + pupilId +"'}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(msg) {
    // Do something interesting here.
  }
});

如果你只想使用JavaSctipt而不使用jQuery休闲 链接

Use jQuery AJAX ,
This is good source

$.ajax({
  type: "POST",
  url: "MessagePopup.asmx/SendMessage",
  data: "{subject:'" + subject + "',message:'" + message + ",messageId:'" + messageId + "',pupilId:'" + pupilId +"'}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(msg) {
    // Do something interesting here.
  }
});

If you want just using JavaSctipt without using jQuery fallow this links

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