簡體   English   中英

無法訪問UserControl的CodeBehind類

[英]Can't access UserControl's CodeBehind Class

我有以下代碼行適用於一個用戶控件,而不適用於另一個用戶控件:

Folder_UserControl1 myVar = (Folder_UserControl1)LoadControl(@"~/Folder/UserControl1.ascx");

但不適用於此文件夾:Folder_UserControl22

我收到以下編譯錯誤:

Error   4   The type or namespace name 'Folder_UserControl22' could not be found (are you missing a using directive or an assembly reference?)  

我檢查了所有文件看起來是否相同,它們都是公共的局部類。

我想念什么?

謝謝

我多次遇到此錯誤,這通常歸因於我復制了自定義組件並且沒有費心在aspx頁面頂部注冊新控件的事實。 所以這就是你應該做的...

通用注冊語法:

<%@ Register TagPrefix="Custom" Namespace="CustomControlNamespace" Assembly= "CustomControl" %>

以及MS文檔

http://support.microsoft.com/kb/321749

當然,這意味着您可以從那時起將自定義控件包括在主代碼中,如下所示:

<Custom:CustomControl id="CustomControl1" parameter1="value1" parameter2="value2" runat="server"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM