我如何...从javascript调用实例方法 [英] How do I... call the instance method from javascript

查看:58
本文介绍了我如何...从javascript调用实例方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何...从javascript方法调用实例方法



i希望根据javascript中的条件调用C#中的实例方法

How do I... call the instance method from javascript method

i want to call the instance method in C# based on condition in javascript

推荐答案

你永远不会从Javascript调用任何C#方法。这个问题表明对Web操作缺乏了解。这些方法在服务器端,Javascript在客户端工作。



但是你可以向服务器端发送HTTP请求并接收HTTP响应。当然,在服务器端,您应该有一些旨在处理此类请求的代码。您可以使用Ajax: http://en.wikipedia.org/wiki/Ajax_(programming) [< a href =http://en.wikipedia.org/wiki/Ajax_(programming)\"target =_ blanktitle =New Window> ^ ]。



一种方便的方法是使用jQuery Ajax: http://api.jquery.com/jquery。 ajax [ ^ ]。



-SA
You never call any C# methods from Javascript. This question demonstrate lack of understanding of the Web operation. These methods are on the server side, and Javascript works on the client side.

But you can send HTTP request to the server side and receive HTTP response. Of course, on the server side you should have some code designed to handle such requests. You can use Ajax: http://en.wikipedia.org/wiki/Ajax_(programming)[^].

One convenient way of doing it would be using jQuery Ajax: http://api.jquery.com/jquery.ajax[^].

—SA


除了解决方案1之外 Sergey Alexandrovich Kryukov [ ^ ],我建议阅读:使用面向对象技术创建高级Web应用程序 [ ^ ]。作者解释了类/结构和JavaScript对象的C#实例之间的区别。
In addition to Solution 1 by Sergey Alexandrovich Kryukov[^], i'd suggest to read this: Create Advanced Web Applications With Object-Oriented Techniques[^]. Author explains the differences between C# instances of classes/structs and JavaScript objects.


使用ajax调用来实现您的要求

在javascript代码中设置参数值基于条件然后使用ajax将值传递给你的c#代码

例如。



函数myfunc()

{

var url =/ Yourajaxfile.aspx?MethodName =+ value;
Use ajax call for achieving your requirement
in javascript code set a parameter value based on condition and then pass that value to your c# code using ajax
eg.

function myfunc()
{
var url = "/Yourajaxfile.aspx?MethodName=" + value;


这篇关于我如何...从javascript调用实例方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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