Asp.net “自定义控件变为通用”;“用户控制”;而不是设计器类中的实际类型
我在ASP.NET(代码隐藏中的VB.NET)中有一个自定义控件,使用ASCX定义:Asp.net “自定义控件变为通用”;“用户控制”;而不是设计器类中的实际类型,asp.net,vb.net,user-controls,ascx,Asp.net,Vb.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--> 这是在图书馆里设置的。不同的项目在页面中使用该
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="MyControl.ascx.vb" Inherits="Mynamespace.Controls.MyControl" %>
<!-- some html and other custom controls-->
这是在图书馆里设置的。不同的项目在页面中使用该控件:
<%@ 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" />
我如何确保它成为:
Protected WithEvents mycontrol1 As Global.Mynamespace.Controls.MyControl
?确保在
Global.Mynamespace.Controls.MyControl
中定义了MyControl
。它继承了这个名称空间,但似乎应该是在其中定义它的名称空间。当然,还要确保定义了MyCustomProperty 您的ascx文件不可访问,因为它位于库中
您需要将ascx文件保存为库的嵌入式资源,并将其作为外部资源加载到web应用程序中
有关更多信息,请参阅此
如果您想共享您的控件,我建议创建UserControl而不是CustomControl。不幸的是,由于设计器不可用,还有更多的工作要做。我尝试在控件后面的代码中明确指定
Global.Mynamespace.Controls.MyControl
,没有骰子。@MPelletier我已经编辑了我的答案。我希望这有帮助。我不能那样做。这就是我的页面背后的代码。我需要这个。此外,我还有其他自定义控件。我不确定在另一个项目中引用用户控件(相对于常规服务器控件)是否受支持。
Protected WithEvents mycontrol1 As Global.System.Web.UI.UserControl
Protected WithEvents mycontrol1 As Global.Mynamespace.Controls.MyControl