一个比较简单的问题,不过对于我来说有点难!!大家帮帮忙!
<%@ Page Language= "C# " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<script runat= "server ">
protected void Page_Load(object sender, EventArgs e)
{
string aa = Label1.Text;
Label1.Text = "你好世界! ";
}
</script>
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<asp:Label ID= "Label1 " runat= "server " Text= "Label "> </asp:Label>
<asp:Label ID= "Label2 " runat= "server "> <%=aa %> </asp:Label> </div>
</form>
</body>
</html>
注: <%=aa %> 得不到值 <%Response.Write(aa); %> 这样也不行,看错误的提示是没有aa这个变量,不过我定义了变量了,怎么回事???
------解决方案--------------------你的aa是一个局部变量 当然不能使用啊 定义成全局的public就可以了。
public string aa = " ";
protected void Page_Load(object sender, EventArgs e)
{
aa = Label1.Text;
Label1.Text = "你好世界! ";
}