C# 从c到javascript的字符串数组示例不工作
我正在使用asp.net web表单fx3.5,并试图将服务器端字符串数组放入javascript中。我发现了一个简单的例子,它声称是有效的,但对我来说并不适用。在.Serializetemp中无法识别temp变量C# 从c到javascript的字符串数组示例不工作,c#,javascript,asp.net,C#,Javascript,Asp.net,我正在使用asp.net web表单fx3.5,并试图将服务器端字符串数组放入javascript中。我发现了一个简单的例子,它声称是有效的,但对我来说并不适用。在.Serializetemp中无法识别temp变量 temp变量中有什么?无效的如何序列化null?是否尝试过将temp初始化为一些伪数据?这很可能是个错误,因为temp还没有初始化。这是一个JavaScript问题吗?我没有看到任何JavaScript。JSON不是JavaScript。 <%@ Page Language="
temp变量中有什么?无效的如何序列化null?是否尝试过将temp初始化为一些伪数据?这很可能是个错误,因为temp还没有初始化。这是一个JavaScript问题吗?我没有看到任何JavaScript。JSON不是JavaScript。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ShelterExpress.UserInterface.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" language="c#">
string[] temp;
int lengthOfTemp;
public string tempJSON = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(temp);
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
<script runat="server" language="c#">
string[] temp;
int lengthOfTemp;
public string tempJSON;
protected override void OnLoad(EventArgs e)//you have to initialize your temp and tempJSON in a method
{
base.OnLoad(e);
temp = new string[] { "Hi", ",", "ojlovecd" };//Initialize your temp here
tempJSON = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(temp);
}
</script>