开发者

can't access a control in my form when I disable viewstate in asp.net and my viewstate is too bulky I don't want to enable it

I want to disable my viewstate in a form because its too bulky (about 1mb per page) due to retrieving some data from database and in other place on the same form I want to access a control from my master page. but when I set viewstate of Listview to false I'll get following error :

Object reference not set to an instance of an object.

what should I do in this situation? veiwstate is too damn bulky and here is what I've written for accessing particular control :

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")
                {

      开发者_如何学JAVA              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


you can disable viewstate for entire page and selectively enable it for your control as explained here

https://web.archive.org/web/20211020153326/https://www.4guysfromrolla.com/articles/071410-1.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜