繁体   English   中英

无法访问UserControl的CodeBehind类

[英]Can't access UserControl's CodeBehind Class

我有以下代码行适用于一个用户控件,而不适用于另一个用户控件:

Folder_UserControl1 myVar = (Folder_UserControl1)LoadControl(@"~/Folder/UserControl1.ascx");

但不适用于此文件夹:Folder_UserControl22

我收到以下编译错误:

Error   4   The type or namespace name 'Folder_UserControl22' could not be found (are you missing a using directive or an assembly reference?)  

我检查了所有文件看起来是否相同,它们都是公共的局部类。

我想念什么?

谢谢

我多次遇到此错误,这通常归因于我复制了自定义组件并且没有费心在aspx页面顶部注册新控件的事实。 所以这就是你应该做的...

通用注册语法:

<%@ Register TagPrefix="Custom" Namespace="CustomControlNamespace" Assembly= "CustomControl" %>

以及MS文档

http://support.microsoft.com/kb/321749

当然,这意味着您可以从那时起将自定义控件包括在主代码中,如下所示:

<Custom:CustomControl id="CustomControl1" parameter1="value1" parameter2="value2" runat="server"/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM