从 JavaScript 调用 ASP.NET 代码隐藏方法
有人可以告诉我如何从客户端 JavaScript 调用 ASP.NET 代码隐藏方法吗?
谢谢
Can someone please tell me how I can invoke a ASP.NET codebehind method from client-side JavaScript?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是一篇关于如何对代码隐藏方法进行 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
我一直使用页面方法。他们都很好。
您可以阅读 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/
使用更新面板控件是最简单的方法,但您可以将页面发布到服务器并使用 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.
使用 jQuery AJAX ,
这是一个很好的来源
如果你只想使用JavaSctipt而不使用jQuery休闲 此链接
Use jQuery AJAX ,
This is good source
If you want just using JavaSctipt without using jQuery fallow this links