在我的web应用程序中发生了一些奇怪的事情。我有我用简单的持有对象的集合持有两个变量的静态词典:时间流逝时丢失键值对的字典
static Dictionary<string, linkButtonObject> linkButtonDictonary = new Dictionary<string, linkButtonObject>();
我跟了LinkButton一个gridview,大约每一个数据与它在字典button.UniqueId相关:
protected void hoursReportGridView_OnRowDataBound(Object sender, GridViewRowEventArgs e)
{
LinkButton btn = (LinkButton)e.Row.FindControl("taskLinkButton");
linkButtonObject currentRow = new linkButtonObject();
currentRow.storyNumber = e.Row.Cells[3].Text;
currentRow.TaskName = e.Row.Cells[5].Text;
linkButtonDictonary.Add(btn.UniqueID, currentRow);
}
然后当LinkButton的点击我拉查找在使用唯一ID的字典中的值,在SQL查询中使用它们,并使用检索到的数据来填充一个gridview,标签,并显示一个弹出:
protected void taskLinkButton_Click(object sender, EventArgs e)
{
//create linkbutton object from sender
LinkButton btn = (LinkButton)sender;
//get a list of data relevant to column
string[] infoData = getInfoData(linkButtonDictonary[btn.UniqueID].storyNumber,
linkButtonDictonary[btn.UniqueID].TaskName);
//assign content of list to labels and gridview
productDatabaseLabel.Text = infoData[0];
storyNumberDatabaseLabel.Text = infoData[1];
taskDatabaseLabel.Text = infoData[2];
pointPersonDatabaseLabel.Text = infoData[3];
SqlDataSource6.SelectParameters["storynumber"].DefaultValue = linkButtonDictonary[btn.UniqueID].storyNumber;
SqlDataSource6.SelectParameters["tasktitle"].DefaultValue = linkButtonDictonary[btn.UniqueID].TaskName;
infoGridView.DataBind();
//show popup
MPE.Show();
}
这一切都很好,我可以点击任何链接按钮,他们正确地创建和填充弹出并显示它。
我的问题是,如果我离开这个页面闲置不用几minuites然后单击一个LinkButton我得到的错误:
什么我做错了,我该如何解决?
为什么字典被声明为静态?如果您删除了静态修饰符,是否会发生此问题? –
如果我删除静态我每次都会得到异常。 –
它有什么特殊之处? KeyNotFound或null? –