如何从javascript函数将参数传递给c#方法 [英] how to pass parameter to c# method from javascript function

查看:65
本文介绍了如何从javascript函数将参数传递给c#方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些像这样的javascript函数 -

I have some javascript function like this-

function updateVaues(paramValues)
{
  document.getElemntById('<%= txtRequisitionNo.ClientID %>').value=paramValues[0];
 //to fill gridviewItem I am calling c# method from javascript as--
  <% fillGrid(paramValues[0]); %>

}





但是我收到paramValues不存在的错误



然后如何在c#



But I am getting error that paramValues does not exist

Then how can I pass paramValues[0] to fillGrid() in c#

推荐答案

你不能这样做。试想一下:Javascript是在客户端执行的,而C#代码是服务器端的代码。客户端和服务器端之间发生的任何事情都可能是呼叫。服务器端代码仅用于响应来自客户端的某些HTTP请求。特别是,您可以使用Ajax发送请求。请参阅:

http://en.wikipedia.org/wiki/Ajax_%28programming %29 [ ^ ]。



使用Ajax发送HTTP请求的一种便捷方法是使用jQuery .ajax()

https://api.jquery.com/jQuery.ajax [ ^ ]。



- SA
You cannot do it. Just think about it: Javascript is executed on client side, and C# code is one the server side. Whatever happens between client and server side could be anything but not "call". The server-side code only works in response to some HTTP request from the client side. In particular, you can use Ajax to send a request. Please see:
http://en.wikipedia.org/wiki/Ajax_%28programming%29[^].

One convenient way to send an HTTP request using Ajax is using jQuery .ajax():
https://api.jquery.com/jQuery.ajax[^].

—SA


http://www.aspsnippets.com/forums/Articles/Pass-function-as-argument-or-parameter-in-JavaScript.aspx [ ^ ]



-KR
http://www.aspsnippets.com/forums/Articles/Pass-function-as-argument-or-parameter-in-JavaScript.aspx[^]

-KR


参考:

如何将javascript变量用于ASP.NET中的aspx.cs代码 [ ^ ]

这个可以提供帮助。
Refer:
How to use javascript variable into aspx.cs code in ASP.NET[^]
This may help.


这篇关于如何从javascript函数将参数传递给c#方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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