我有一個ASP.NET網站,而不是Web應用程序,我已經建立了一個自定義CompareValidator
這是能夠獲得它自己的命名容器的外面的:如何讓自定義控件可用於ASP.NET網站?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;
public class GlobalCompareValidator : CompareValidator
{
new protected void CheckControlValidationProperty(string name, string propertyName)
{
Control control = this.Page.NamingContainer.FindControl(name);
if (control == null)
{
throw new HttpException("Validator_control_not_found");
}
if (BaseValidator.GetValidationProperty(control) == null)
{
throw new HttpException("Validator_bad_control_type");
}
}
}
和存在於App_Code
目錄代碼。現在,我想用這個新的自定義控制的ASCX頁面上是這樣的:
<me:GlobalCompareValidator ID="compareValidator" CssClass="errorMessage" Display="None"
EnableClientScript="false" Text=" " ValidationGroup="LHError" runat="server" />
然而,試圖註冊的組件時使用它:
<%@ Register TagPrefix="me" Namespace="MyNamespace" Assembly="MyAssembly" %>
我得到這個錯誤:
Could not load file or assembly '...' or one of its dependencies. The system cannot find the file specified.
現在,這並不是真的那麼令人驚訝,因爲ASP.NET網站並沒有真正生成這樣的程序集。但是,如果我將Assembly
標籤關閉,則無法找到GlobalCompareValidator
。當然,它也可能找不到Assembly
標籤,但是這個錯誤很可能隱藏在找不到組件的事實中。
如何在世界中獲得可用於ASP.NET網站的自定義控件?