i'm using asp.net web form fx3.5 and i'm trying to get my server-side string array into my javascript. i found a simple example that claims to work but it doesn't for me. temp variable is not recognized in ().Serialize(temp);
Here's the reference article
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ShelterExpress.UserInterface.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTM开发者_Go百科L 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>
精彩评论