自定义控件变为通用"UserControl",而不是Designer类中的实际类型

MPe*_*ier 11 vb.net asp.net user-controls ascx

我在ASP.NET中有一个自定义控件(后面的代码中的VB.NET),用ASCX定义:

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="MyControl.ascx.vb" Inherits="Mynamespace.Controls.MyControl" %>

<!-- some html and other custom controls-->
Run Code Online (Sandbox Code Playgroud)

在代码背后:

Namespace Controls

    Public Class MyControl
        Inherits System.Web.UI.UserControl
Run Code Online (Sandbox Code Playgroud)

这是在库中设置的.另一个项目在页面中使用该控件:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="mypage.aspx.vb" 
    Inherits="myproject.mypage" culture="auto" meta:resourcekey="Page" uiculture="auto" 
    Transaction="RequiresNew" MasterPageFile="Mynamespace.Master" 
    Theme="ThemeBase2" StylesheetTheme="ThemeBase2" %>

<%@ Register tagprefix="Controls" tagname="MyControl" src="../Controls/MyControl.ascx" %>

<%-- some asp.net --%>

<Controls:MyControl ID="mycontrol1" runat="server" 
                    MyCustomProperty="value" />
Run Code Online (Sandbox Code Playgroud)

但是,当我构建时,我得到一个错误说

'MyCustomProperty'不是'System.Web.UI.UserControl'的成员.

在designer.vb页面中,我看到:

Protected WithEvents mycontrol1 As Global.System.Web.UI.UserControl
Run Code Online (Sandbox Code Playgroud)

我如何确保它成为:

Protected WithEvents mycontrol1 As Global.Mynamespace.Controls.MyControl
Run Code Online (Sandbox Code Playgroud)

Tro*_*ers 1

您的 ascx 文件无法访问,因为它位于库中

您需要将 ascx 文件保存为库的嵌入资源,并将其作为外部资源加载到 Web 应用程序中。

您可以查阅此链接以获取更多信息。

如果您想共享您的控件,我建议创建 UserControl 而不是 CustomControl。不幸的是,由于设计器不可用,还有更多工作要做