2015-12-14 28 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