【发布时间】:2011-03-20 04:37:04
【问题描述】:
我想禁用表单中的视图状态,因为它太庞大(每页约 1mb),因为从数据库中检索一些数据,并且在同一表单上的其他地方我想从我的母版页访问控件。 但是当我将 Listview 的 viewstate 设置为 false 时,我会收到以下错误:
对象引用未设置为 对象的实例。
在这种情况下我该怎么办? veiwstate 太笨重了 这是我为访问特定控件而编写的内容:
Control cc = Page.Master.FindControl("mainContent").FindControl("ListView1").FindControl("itemPlaceholderContainer");
foreach (Control ListItemctrl in cc.Controls)
{
Control lblNewsId = ListItemctrl.FindControl("lblNewsID");
if (lblNewsId != null)
{
Type t = lblNewsId.GetType();
if (t.FullName == "System.Web.UI.WebControls.Label")
{
string newsID = ((Label)lblNewsId).Text;
foreach (Control childCtrl in ListItemctrl.Controls)
{
CheckBox ctrlCB = childCtrl.FindControl("chkItem") as CheckBox;
if (ctrlCB.Checked)
{
//based on DDLAction we will do the things ;)
}
if (childCtrl.FindControl("chkItem") != null)
break;
}//end foreach childCtrl
}
}//end outer if
}//end foreach listItenctrl
【问题讨论】: