使用FindControl出现未将对象引用设置到对象的实例 错误的解决办法
经过一番搜索,在forums.asp.net中找到了答案,以下引用的是bitmask的说法:
...becasue the Content controls themselves dissapear after the master page rearranges the page. You can use the ContentPlaceHolders, or the <form> on the MasterPage if there are no INamingContainers between the form and the control you need.
所以以上的代码应该改成:
TextBox tb = (TextBox)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("TextBox1");
资料引用:http://www.knowsky.com/339938.html
本文介绍了一个关于使用FindControl方法时遇到的“未将对象引用设置到对象的实例”错误,并给出了正确的解决办法。通过调整代码结构,利用MasterPage和ContentPlaceHolder来定位控件,可以避免错误的发生。

2万+

被折叠的 条评论
为什么被折叠?



