从Java脚本调用C#代码 [英] Call C# Code From Javascript

查看:112
本文介绍了从Java脚本调用C#代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从javascript调用特定的c#函数.现在,我在javascript中使用回发​​功能,并为该回发创建会话.所以页面加载事件我正在检查该会话并调用特定功能.但是我不喜欢那种方法.因为我们不能调用特定的函数.任何想法专家....

I want to call a particular c# function from javascript . Now i am using postback function in javascript and creating a session for that postback. so page load event i am checking that session and call particular function . But i dont like that method . Becuse we cant call a particular function. Any Idea Guys ....

推荐答案

是的,您可以使Web方法类似..您可以创建Web服务来调用服务器端代码
yes, you can make web method like.. you can create web service to call to server side code
[WebMethod]
public static String SetName(string name)
{
    return "Your String"
}



然后像这样调用javascript.



and then call in javascript like..

PageMethods.SetName(parameterValueIfAny, onSuccessMethod,onFailMethod);



这也是必需的



this also required

<asp:scriptmanager id="ScriptMgr" runat="server" enablepagemethods="true" xmlns:asp="#unknown"> </asp:scriptmanager>


请参考以下主题:
如何在服务器后面调用代码客户端javascript函数提供的方法 [从Java脚本函数调用C#代码背后的方法 [通过ASP中的Javascript调用C#函数. NET [使用jQuery调用ASP.NET AJAX页面方法–通过示例 [
Please refer following threads:
How to call code behind server method from a client side javascript function[^]
call a C# code behind method from a Java Script function[^]
Calling C# function through Javascript in ASP.NET[^]
Using jQuery to Call ASP.NET AJAX Page Methods – By Example[^]


有几种方法通过客户端与服务器端进行交互(Javascript):
1.
XMLHttpRequest [回调 [ Web服务调用 [ PageMethod [
There are few ways to interact with server side through client side(Javascript):
1. XMLHttpRequest[^]
2. Callback[^]
3. WebService call[^]
4. PageMethod[^]


这篇关于从Java脚本调用C#代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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