一个非常简单的程序:两个label,一个button.按button会加1。 我已经设置EnableViewState= "false " 而且用trace 查看control tree 下hidden 的大小一个为20,一个为0。但每个label的text显示的值都会加1。真的不明白。请大家指点一下!
代码如下:是在webSite 下运行
<%@ Page Language= "C# " Trace= "true "%>
<!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 btnAdd_Click(object sender, EventArgs e)
{
lblCounter.Text = (Int32.Parse(lblCounter.Text) + 1).ToString();
lable2.Text = (Int32.Parse(lblCounter.Text) + 1).ToString();
}
</script>
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head id= "Head1 " runat= "server ">
<title> Show View State </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<asp:Button
id= "btnAdd "
Text= "Add "
OnClick= "btnAdd_Click "
Runat= "server " />
<asp:Label ID= "lable2 " EnableViewState= "false " runat= "server " > </asp:Label>
<asp:Label
id= "lblCounter "
Text= "0 "
Runat= "server " />
</div>
</form>
</body>
</html>
------解决方案--------------------------------------------------------
lblCounter.Text = (Int32.Parse(lblCounter.Text) + 1).ToString();
lable2.Text = (Int32.Parse(lblCounter.Text) + 1).ToString();
页面的Lable控件你都赋值了啊