ASP.NET UserControl对象上的FindControl() [英] FindControl() on ASP.NET UserControl Objects

查看:61
本文介绍了ASP.NET UserControl对象上的FindControl()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我创建了一个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

推荐答案

您好,

为了在页面中声明包含控件,您使用了@Register
页面顶部的
指令。但是对于程序设计,将会有一个改变的b $ b。您将使用@Reference指令。该指令仅包含一个

属性,Page或Control。此属性的值指定包含控件的文件



动态补充期间此页面应链接到的页面。这一步非常重要,否则你将获得

编译错误CS0246,表明找不到类名或类型。

<%@ Reference Control =" ./ controls /SiteHeader.ascx"%>

有关详细信息,请参阅以下链接:
http://forums.microsoft.com/MSDN/Sho...63704&SiteID=1

希望这有帮助

-

谢谢和问候。

Manish Bafna。

MCP和MCTS。


" Alex Maghen"写道:
Hi,
For declarative inclusion of control in the page, you used @Register
directive at the top of the page. But for programatic there is going to be a
change. You will use @Reference directive. This directive takaes only one
attribute, Page or Control. The value of this attribute specifies the file
that contains the control or the page that this page should link to during
dynamic compliation. This step is very important, otherwise your will get
Compiler Error CS0246 indicating that class name or type not found.
<%@ Reference Control="./controls/SiteHeader.ascx"%>
For more details refer following link:
http://forums.microsoft.com/MSDN/Sho...63704&SiteID=1
Hope this helps
--
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"Alex Maghen" wrote:

嗨。我创建了一个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


Manish -


感谢您的帮助...但我还需要更多。所以我在ASPX的顶部放置了

<%@ Reference Control =&。/ Controls / GalleryThumb.ascx"%>

指令。那个ASPX有一个C#代码隐藏.CS页面。

我仍​​然从.CS页面得到同样的错误。有什么东西

具体我必须在实际的.CS文件中使类型可用,或

应该是参考来自ASPC的指令也在其

代码隐藏中提供类型?


Alex


" ; Manish Bafna写道:
Manish -

Thanks for the help... but I still need more. So I placed the
<%@ Reference Control="./Controls/GalleryThumb.ascx"%>
directive at the top of the ASPX. That ASPX has a C# code-behind .CS page.
I''m still getting the same error from the .CS page. Is there something
specific I have to do in the actual .CS file to make the type available, or
should the "Reference" directive from the ASPC make the type available in its
code-behind as well?

Alex

"Manish Bafna" wrote:



为了在页面中声明包含控件,你使用了@Register

指令在页面顶部。但是对于程序设计,将会有一个改变的b $ b。您将使用@Reference指令。该指令仅包含一个

属性,Page或Control。此属性的值指定包含控件的文件



动态补充期间此页面应链接到的页面。这一步非常重要,否则你将获得

编译错误CS0246,表明找不到类名或类型。

<%@ Reference Control =" ./ controls /SiteHeader.ascx"%>

有关详细信息,请参阅以下链接:
http://forums.microsoft.com/MSDN/Sho...63704&SiteID=1

希望这有帮助

-

谢谢和问候。

Manish Bafna。

MCP和MCTS。


" Alex Maghen"写道:
Hi,
For declarative inclusion of control in the page, you used @Register
directive at the top of the page. But for programatic there is going to be a
change. You will use @Reference directive. This directive takaes only one
attribute, Page or Control. The value of this attribute specifies the file
that contains the control or the page that this page should link to during
dynamic compliation. This step is very important, otherwise your will get
Compiler Error CS0246 indicating that class name or type not found.
<%@ Reference Control="./controls/SiteHeader.ascx"%>
For more details refer following link:
http://forums.microsoft.com/MSDN/Sho...63704&SiteID=1
Hope this helps
--
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"Alex Maghen" wrote:

嗨。我创建了一个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


还有一件事,Manish -


我尝试构建一个没有代码隐藏的ASPX然后,它奏效了。甚至更多,一旦它在那里工作,我可以运行另一个文件与代码支持

并且那个也工作(我猜因为ASCX已经成功

编译)。所以现在,我如何使用代码隐藏的永久性工作?


Alex

Manish Bafna写道:
One more thing, Manish -

I tried building an ASPX WITHOUT a code-behind and then, it worked. Even
more, once it worked there, I could run the other file WITH the code-behind
and that one worked too (I guess because the ASCX had already successfully
compiled). So now, how do I make it work WITH the code-behind permanenetly?

Alex
"Manish Bafna" wrote:



为了在页面中声明包含控件,你使用了@Register

指令在页面顶部。但是对于程序设计,将会有一个改变的b $ b。您将使用@Reference指令。该指令仅包含一个

属性,Page或Control。此属性的值指定包含控件的文件



动态补充期间此页面应链接到的页面。这一步非常重要,否则你将获得

编译错误CS0246,表明找不到类名或类型。

<%@ Reference Control =" ./ controls /SiteHeader.ascx"%>

有关详细信息,请参阅以下链接:
http://forums.microsoft.com/MSDN/Sho...63704&SiteID=1

希望这有帮助

-

谢谢和问候。

Manish Bafna。

MCP和MCTS。


" Alex Maghen"写道:
Hi,
For declarative inclusion of control in the page, you used @Register
directive at the top of the page. But for programatic there is going to be a
change. You will use @Reference directive. This directive takaes only one
attribute, Page or Control. The value of this attribute specifies the file
that contains the control or the page that this page should link to during
dynamic compliation. This step is very important, otherwise your will get
Compiler Error CS0246 indicating that class name or type not found.
<%@ Reference Control="./controls/SiteHeader.ascx"%>
For more details refer following link:
http://forums.microsoft.com/MSDN/Sho...63704&SiteID=1
Hope this helps
--
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"Alex Maghen" wrote:

嗨。我创建了一个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()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆