我想将保护页面加载中的变量传递给客户端JavaScript但是当我尝试
时int d[5][5];
它给我一个错误,上面写着:“预期表达”,在这种情况下我该怎么办?我怎样才能传递变量?
我的代码:
var variable=<%=count %>
<script runat="server">
public int countSK = 0;
public int countFaze = 0;
public int countAstralis = 0;
public int countNip = 0;
public int countCloud = 0;
public int countG2 = 0;
public int countNorth = 0;
public int countVP = 0;
public int countMouz = 0;
public int countLiquid = 0;
public int countGambit = 0;
public int countFnatic = 0;
public int countRene = 0;
public int countEnvy = 0;
public int countNavi = 0;
protected void Page_Load(object sender, EventArgs e)
{
if ((string)Session["username"] != "ADMIN")
{
Response.Redirect("NotAdmin.aspx");
Response.End();
}
string conStr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\KatzirDatabase.mdf;Integrated Security=True;User Instance=True";
string cmdStr = "SELECT favT FROM tbl";
SqlConnection conObj = new SqlConnection(conStr);
SqlCommand cmdObj = new SqlCommand(cmdStr, conObj);
conObj.Open();
SqlDataReader dr = cmdObj.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
string team= dr["favT"].ToString();
switch (team)
{
case "sk": countSK++; break;
case "faze": countFaze++; break;
case "astralis": countAstralis++; break;
case "nip": countNip++; break;
case "cloud9": countCloud++; break;
case "g2": countG2++; break;
case "north": countNorth++; break;
case "vp": countVP++; break;
case "mouz": countMouz++; break;
case "liquid": countLiquid++; break;
case "gambit": countGambit++; break;
case "fnatic": countFnatic++; break;
case "renegades": countRene++; break;
case "envyus": countEnvy++; break;
case "navi": countNavi++; break;
}
}
}
conObj.Close();
}
在这里,我添加了我的代码,如果你能找到我的问题我会非常感谢,谢谢!!
答案 0 :(得分:0)
请使用以下内容,并确保将您的变量声明为班级顶部的公共
var variable='<%=count %>'
答案 1 :(得分:0)
您可能缺少单引号:var variable = '<%=count%>';
然后在页面上将count定义为公共属性