我已經爲我的項目添加了一個名爲HomePageItem的Web用戶控件,並且我試圖以編程方式從名爲LandingPage.aspx的頁面創建它的新實例。由於某種原因該課程不可見。我只是得到,說的生成錯誤:無法從aspx頁面引用UserControl
類型或命名空間名稱「Controls_HomePageItem」找不到(是否缺少using指令或程序集引用?)
這是代碼行我LandingPage.aspx文件:
Controls_HomePageItem hpi = new Controls_HomePageItem();
這裏是整個HomePageItem.ascx文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Controls_HomePageItem : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
我試圖把所謂的主頁0命名空間中的控制 像這樣:
namespace HomePage {
public partial class Controls_HomePageItem : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
然後引用該控制像這樣在LandingPage.aspx HomePage.Controls_HomePageItem HPI =新HomePage.Controls_HomePageItem();
,我嘗試using語句在頂部:
using HomePage;
同樣的問題依然。我甚至不能從LandingPage.aspx看到主頁命名空間
請幫忙。
TIA
這就是文件是如何由VS2008創建的。但我會嘗試手動快速插入它。 – n4rzul 2011-05-23 07:17:35
@ n4rzul;你想在代碼後面添加usercontrol? – 2011-05-23 07:18:28
@穆罕默德:我想programmaticaly在我的一個頁面中創建一個usercontrol的實例,但看不到該類。是的,它在我的頁面後面的代碼中,.cs文件,而不是aspx文件。 – n4rzul 2011-05-23 07:34:01