我在我的 Vista 盒子 (IIS7) 上开发了一个 ASP.NET 应用程序。在我将它部署到产品服务器 (W2K3/IIS6) 之前它工作正常。部署后,我会得到一致的“对象引用未设置为对象的实例”。从我的 ViewState 对象读取时,该对象确定按钮是显示“开”还是“关”图像。
页面加载的代码将 ViewState 初始化为 on:
if (!IsPostBack)
{
ViewState["ButtonState"] = true;
}
然后我在 OnPreRender 方法中检查按钮的状态:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if ((bool)ViewState["ButtonState"])
{
MyButton.ImageUrl = Constants.ButtonIcon;
}
else
{
MyButton.ImageUrl = Constants.NoButtonIcon;
}
}
为了在按钮的状态之间切换,我捕获了按钮的单击并切换 ViewState 中的值:
protected void MyButton_Click(object sender, ImageClickEventArgs e)
{
ViewState["ButtonState"] = !(bool)ViewState["ButtonState"];
}
在开发盒上,这非常有效。但是,在 live box 上,页面加载正确,但是当您单击按钮(或实际上导致回发的任何其他按钮)时,您会在回发后收到错误消息。
任何人都可以帮忙吗?