2015-12-14 57 views
10

我(在VB.NET代码后面)在ASP.NET自定义控件并非其实际的类型,与ASCX定义:自定义控制成为通用的“用户控件”,并在设计类

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

<!-- some html and other custom controls--> 

而且在代码背后:

Namespace Controls 

    Public Class MyControl 
     Inherits System.Web.UI.UserControl 

这是设置在一个库中。不同的项目使用控制在一个页面:

<%@ 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" /> 

然而,当我建,我得到一个错误说

“MyCustomProperty”不是“System.Web.UI.UserControl成员”。

而在designer.vb页我看到:

Protected WithEvents mycontrol1 As Global.System.Web.UI.UserControl 

我如何确保它成为:

Protected WithEvents mycontrol1 As Global.Mynamespace.Controls.MyControl 

+0

我不确定在另一个项目中引用*用户控件*(而不是常规服务器控件)是受支持的方案。 –

回答

1

你的ascx文件无法访问。

你可以参考这个link了解更多信息。

如果你想共享你的控件,我建议创建UserControl而不是CustomControl。不幸的是,有更多的工作,因为设计师不可用

2

确保MyControlGlobal.Mynamespace.Controls.MyControl内定义。它继承了这个命名空间,但它似乎应该是它所在的命名空间。另外,确保MyCustomProperty被定义,当然。因为它是在一个库中

您需要的ASCX文件保存为库的嵌入式资源和加载它在你的web应用的extern资源

+0

我试着在控件背后的代码中明确指定'Global.Mynamespace.Controls.MyControl',没有骰子。 – MPelletier

+0

@MPelletier我编辑了我的答案。我希望这有帮助。 – ic3man7019

+0

我不能那样做。这是我的页面代码。我需要它。另外,我还有其他自定义控件。 – MPelletier