How do I pass an array I have created on the server side onto the client side for manipulation by Javascript?
如何将我在服务器端创建的数组传递到客户端以供Javascript操作?
Any pseudo code will help
任何伪代码都会有所帮助
5 个解决方案
#1
3
You'll need to embed it as a javascript array declaration into the page. There are a number of ways to do this, but it generally means turning the array into text that you write to the page, probably using the ClientScriptManager.
您需要将其作为javascript数组声明嵌入到页面中。有很多方法可以做到这一点,但它通常意味着将数组转换为您写入页面的文本,可能使用ClientScriptManager。
I'm hoping for better javascript integration in a upcoming verison of ASP.Net. Moving the value of a server variable —any server variable— to the client ought to be supported with a simple, one-line function call. Not the back-flips we need right now.
我希望在即将推出的ASP.Net版本中更好地集成javascript。将服务器变量-any服务器变量的值移动到客户端应该通过简单的单行函数调用来支持。不是我们现在需要的翻转。
#2
3
Another way would be to use the RegisterArrayDeclaration method of the Page object (deprecated) or in the ClientScriptManager class. See MSDN for details.
另一种方法是使用Page对象的RegisterArrayDeclaration方法(不建议使用)或ClientScriptManager类。有关详细信息,请参阅MSDN
#3
3
The way I do it is like this:
我这样做是这样的:
aspx:
private string buttonarray = "'but1','but2','but3','but4'";
public string Buttonarray
{
get { return buttonarray; }
}
javascript
var buttonarray = new Array(<%=Buttonarray%>);
I hope this helps.
我希望这有帮助。
#4
2
Convert it to string representation of a javascript array ("['val1','val2','val3']") and shove it into the value field of a hidden input.
将其转换为javascript数组的字符串表示形式(“['val1','val2','val3']”)并将其转换为隐藏输入的值字段。
#5
0
Easiest way is to convert it to json. Then just put it at the top of the page in a variable. I've found this the best json implementation for .net: http://litjson.sourceforge.net/
最简单的方法是将其转换为json。然后将它放在变量中的页面顶部。我发现这是.net最好的json实现:http://litjson.sourceforge.net/
#1
3
You'll need to embed it as a javascript array declaration into the page. There are a number of ways to do this, but it generally means turning the array into text that you write to the page, probably using the ClientScriptManager.
您需要将其作为javascript数组声明嵌入到页面中。有很多方法可以做到这一点,但它通常意味着将数组转换为您写入页面的文本,可能使用ClientScriptManager。
I'm hoping for better javascript integration in a upcoming verison of ASP.Net. Moving the value of a server variable —any server variable— to the client ought to be supported with a simple, one-line function call. Not the back-flips we need right now.
我希望在即将推出的ASP.Net版本中更好地集成javascript。将服务器变量-any服务器变量的值移动到客户端应该通过简单的单行函数调用来支持。不是我们现在需要的翻转。
#2
3
Another way would be to use the RegisterArrayDeclaration method of the Page object (deprecated) or in the ClientScriptManager class. See MSDN for details.
另一种方法是使用Page对象的RegisterArrayDeclaration方法(不建议使用)或ClientScriptManager类。有关详细信息,请参阅MSDN
#3
3
The way I do it is like this:
我这样做是这样的:
aspx:
private string buttonarray = "'but1','but2','but3','but4'";
public string Buttonarray
{
get { return buttonarray; }
}
javascript
var buttonarray = new Array(<%=Buttonarray%>);
I hope this helps.
我希望这有帮助。
#4
2
Convert it to string representation of a javascript array ("['val1','val2','val3']") and shove it into the value field of a hidden input.
将其转换为javascript数组的字符串表示形式(“['val1','val2','val3']”)并将其转换为隐藏输入的值字段。
#5
0
Easiest way is to convert it to json. Then just put it at the top of the page in a variable. I've found this the best json implementation for .net: http://litjson.sourceforge.net/
最简单的方法是将其转换为json。然后将它放在变量中的页面顶部。我发现这是.net最好的json实现:http://litjson.sourceforge.net/