是否可以将Aspx代码后面的数据/数据集合传递给JavaScript? [英] Is it Possible to pass Array / Collection of Data From Aspx Code Behind to JavaScript ?

查看:51
本文介绍了是否可以将Aspx代码后面的数据/数据集合传递给JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过示例显示....



< asp:Button id =runat =serveronclientClick =JavaScript:PassVal(intArrayval );>



Jscript

-----



PassVal(arrrayval){

}

I show through an Example ....

<asp:Button id="" runat="server" onclientClick="JavaScript : PassVal(intArrayval);">

Jscript
-----

PassVal(arrrayval){
}

推荐答案

它没有解决问题本身但是如果你只有一个数组就可以解决问题pass:您可以向JavaScript函数发送任意数量的参数,并通过arguments特殊变量访问它们。它变得类似于接受可变数量的参数的函数,具有相同的优点和问题(例如,你必须最后传递数组,并且如前所述,你只能传递一个)。



这是一个示例JavaScript函数:



It's not solving the issue itself but it solves the problem if you have only one array to pass: you can send an arbitrary number of parameters to a JavaScript function, and access them through the arguments special variable. It becomes analogous to a function accepting a variable number of arguments, with the same advantages and problems (for instance, you have to pass the array last, and as mentioned earlier you can only pass one).

Here's an example JavaScript function:

function foo()
{
    var stringArgs = [];
    for (var i = 0; i < arguments.length; i++)
        stringArgs.push(arguments[i]);

    // do stuff with stringArgs
}





你可以用C#这样叫它:





And you'd call it from C# like this:

List<string> arguments = new List<string>();
arguments.Add("foo");
arguments.Add("bar");
webBrowser.InvokeScript("foo", arguments.ToArray());





谢谢,

-RG



Thanks,
-RG


你可以在这里做[通过使用viewstates或任何statemgt技术保存数据并将其设置为隐藏字段]

现在使用它隐藏字段,您可以访问javascript代码中的数据
you can do onething here[ by using viewstates or any of the statemgt technique hold data and set it to hidden field]
now using that hidden field you can access data in javascript code


这篇关于是否可以将Aspx代码后面的数据/数据集合传递给JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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