问题描述
您好。我创建了一个UserControl(MyUC)。我已经把一堆
的实例控制在一个页面上(Defaul.aspx)。控件工作正常。
现在,我希望能够使用FindControl()从我的Default.aspx中可以看出
如下:
MyUC C =(MyUC)this.FindControl(" SomeID");
当我尝试运行它时,我收到错误:
找不到类型或命名空间名称''MyUC''(你错过了吗? >
使用指令或汇编引用?)
此错误出现在FindControl()上。线。此外,在实际的VS编辑器中,Default.aspx代码中的
,对类型MyUC的引用。 *做*显示在
绿色,似乎被认可。但是当我运行它时,我得到了这个错误。
所以我很困惑的是,我如何推荐这种新的控制类型我已经
创建(MyUC)。
还有一个注释:我的文件(ASPX页面,MyUC.ascx等)都没有
名称空间。我刚从VS中创建了文件。是否有一些默认的
命名空间我必须使用什么?
非常感谢!
Alex
Hi. I have created a UserControl ("MyUC"). I''ve put a bunch of instances of
that control on a Page ("Defaul.aspx"). The control works fine.
Now, I want to be able to use "FindControl()" from within my Default.aspx as
follows:
MyUC C = (MyUC)this.FindControl("SomeID");
When I try to run this, I get error:
"The type or namespace name ''MyUC'' could not be found (are you missing a
using directive or an assembly reference?)"
This error is on that "FindControl()" line. Also, in the actual VS editor,
in the Default.aspx code, the references to the type "MyUC" *do* show up in
green and seem to be recognized. But when I run it, I get this error.
So what I''m confused about is, how do I refernce this new control type I''ve
created ("MyUC").
One more note: None of my files (the ASPX pages, MyUC.ascx, etc.) have
namespaces. I just created the files from within VS. Is there some default
namespace I have to use or something?
Much appreciated!
Alex
推荐答案
这篇关于ASP.NET UserControl对象上的FindControl()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!