我怎样才能从Javascript调用C#方法 [英] how i can cll method c# from Javascript

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

问题描述

大家好
我怎么能
调用void C#
无效名称为test
来自Javascript

或来自客户端事件
感谢您的帮助

hi everyone
how i can
call void c#
the void name is test
from Javascript

or from client side events
thanks for any help

推荐答案

http://www .dotnetcurry.com/ShowArticle.aspx?ID = 109 [ ^ ]

希望以上信息对您有所帮助.如果您还有其他顾虑,请告诉我.
http://www.dotnetcurry.com/ShowArticle.aspx?ID=109[^]

I hope the above information will be helpful. If you have more concerns, please let me know.


我不认为可以直接做您尝试做的事情.服务器端功能位于服务器端,而客户端功能则位于客户端.使任何服务器端代码运行的唯一方法是提交表单. ASP.NET展开HTTP标头,解压缩隐藏的ViewState变量,重新实例化对象,然后根据上述所有决定要引发的事件.

您可以做的是让您的Javascript函数设置一个隐藏的表单变量,然后执行form.submit().

然后在服务器上的Page_Load处理程序中,使用Request对象检查此变量的存在和/或值,然后调用适当的服务器端方法.

希望这可以帮助.我不是专家,但是在搜索您的问题时发现了这种方法.如果有人知道其他方式,也请让我知道.

-
AJ
I don''t thing it is possible to directly do the stuff you are trying. Server-side function live on server-side and the client-side function love on the client. The only way to get any server-side code to run is to submit the form. ASP.NET unrolls the HTTP headers, unpacks the hidden ViewState variable, re-instantiates objects, and then decides what events to raise based on all of the above.

What you can do is have your Javascript function set a hidden form variable, then do a form.submit().

Then in your Page_Load handler on the server, use the Request object to check for the presence and/or value of this variable, and call the appropriate server-side method.

Hope this helps. I am not an expert but I found this way while searching for your question. If anyone knows any other way please let me know too.

--
AJ


听起来像您想知道如何从Javascript与服务器对话.
通过客户端(Javascript)与服务器端进行交互的方法很少:
1. XMLHttpRequest [回调 [ Web服务调用 [ PageMethod [
Sounds like you want to know how to talk to server from Javascript.
There are few ways to interact with server side through client side(Javascript):
1. XMLHttpRequest[^]
2. Callback[^]
3. WebService call[^]
4. PageMethod[^]


这篇关于我怎样才能从Javascript调用C#方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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