繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> Asp.Net开发 >> 如何使用FindControl查找内容页上的某个控件?(2)

如何使用FindControl查找内容页上的某个控件?(2)

2007-09-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介:TextBox tb = (TextBox)con.FindControl("TextBox1"); 但con的值为null,这样后续的语句也不可能执行了。问题出在哪里呢? 经过一番搜索,在forums.ASP.net中找到了答案,以下引用的是bitmask的说法: ...becasu...

TextBox tb = (TextBox)con.FindControl("TextBox1");

但con的值为null,这样后续的语句也不可能执行了。问题出在哪里呢?

经过一番搜索,在forums.ASP.net中找到了答案,以下引用的是bitmask的说法:

...becasue the Content controls themselves dissapear after the master page rearranges the page. You can use the ContentPlaceHolders, or the

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

bitmask还在他的博客上写了一篇文章来阐述FindControl方法和INamingContainers接口:

http://www.odetocode.com/Articles/116.ASPx

http://movingboy.cnblogs.com/archive/2006/07/06/444690.HTML

做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。

责任编辑:admin
相关文章