简体   繁体   中英

Can't access UserControl's CodeBehind Class

I have the following line of code that works with one user control and not the other:

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

but it does not work with this: Folder_UserControl22

I get the following compile error:

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

I checked everything the files look identical, both are public partial classes.

What am I missing?

Thanks

I've had this error many times and it is usually down to the fact that I've duplicated custom components and haven't been bothered to register the new control at the top of the aspx page. So this is what you should do...

Generic registration syntax:

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

And the MS documentation

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

And of course, that means you can include the custom controls from then on in the main code like so:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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