且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法加载类型“用户控件"

更新时间:2023-11-30 20:01:22

以下示例显示了对Web UserControl的作用,但对Page,Master Page和WebPart的作用相同:

The following example shows that for a Web UserControl, but it works the same for a Page, a Master Page and a WebPart:

  <!-- change this (ASP.NET Web Site version) -->
 <%@ Control Language="C#" AutoEventWireup="true"
 CodeFile="WebUserControl.ascx.cs"
 Inherits="Controls_WebUserControl" %>

 <!-- into this (ASP.NET Web Application version), or vice versa -->
 <%@ Control Language="C#" AutoEventWireup="true"
 CodeBehind="WebUserControl.ascx.cs"
 Inherits="Controls_WebUserControl" %>

这是您摆脱该烦人的错误所需要做的一切!

That’s all you need to do to get rid of that annoying error!

原因?如果您具有"ASP.NET Web应用程序",则Microsoft需要在Page,Control或Master指令中使用CodeBehind,如果您具有"ASP.NET网站",则编译器将期望使用CodeFile.我不知道为什么存在这种差异,这很烦人,您可以在发现之前永远盯着代码,但这是这种情况的解决方案

The reason? If you have an "ASP.NET Web Application", Microsoft needs CodeBehind in the Page, Control or Master directive, if you have an "ASP.NET Web Site", the compiler expects CodeFile instead. I have no idea why this difference exists, it is very annoying and you can stare forever at your code before you find it, but this is the solution for this scenario