我想知道为什么当我声明一个每次重新加载页面时实现的 public Int 时,int 总是变为 1。
这是我使用的代码。
我在页面加载前声明了 int。每个页面加载的 int 都是 1。它应该是 2、3 等等 ...
public int countIdPrevious;
protected void Page_Load(object sender, EventArgs e)
{
countIdPrevious++;
}
请您参考如下方法:
这是因为字段不包含在 ViewState 中。
把这个字段变成一个ViewState-backed property你会没事的。
