2011-12-16 138 views
4

這是我第一次嘗試構建ASP.NET服務器控件。編寫控制代碼很簡單,但我遇到了試圖在網頁上獲取控件的路障。ASP.NET服務器控制錯誤:未知服務器標記

我在一個項目中構建控件並在另一個項目中引用它。在第二個項目中,我將控件放到工具箱中,並將控件拖放到頁面上。我可以編譯web項目沒有錯誤,但是當我瀏覽網頁我得到這個錯誤:

Parser Error Message: Unknown server tag 'cc1:StandardControl1'.

做一些環顧四周我看到有別人這個問題,因爲各種原因,但沒有一個似乎適用於我的情況。一個解決方案是集添加到寄存器的標籤,但是這不是我的第一個問題:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="another.aspx.vb" Inherits="Educate.another" %> 
<%@ Register Assembly="ServerControlSandbox" Namespace="ServerControlSandbox" TagPrefix="cc1" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <cc1:StandardControl1 runat="server"> 
     </cc1:StandardControl1> 
    </div> 
    </form> 
</body> 
</html> 

另一種解決方案據說它與組件屬性添加到web.config中,再次。但隨着這在我的web.config我仍然得到錯誤:

<controls> 
     <add tagPrefix="cc1" namespace="ServerControlSandbox" assembly="ServerControlSandbox"/> 
       <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
       <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
      </controls> 

我想有一些簡單的我失蹤,但我認爲沒有錯,被我看的例子來看。有沒有人有任何想法?謝謝。

而且,這裏是控制代碼:

namespace ServerControlSandbox 
{ 
    [DefaultProperty("Text")] 
    [ToolboxData("<{0}:StandardControl1 runat=server></{0}:StandardControl1>")] 
    public class StandardControl : WebControl 
    { 
     [Bindable(true)] 
     [Category("Appearance")] 
     [DefaultValue("")] 
     [Localizable(true)] 
     public string Text 
     { 
      get 
      { 
       String s = (String)ViewState["Text"]; 
       return ((s == null) ? "[" + this.ID + "]" : s); 
      } 

      set 
      { 
       ViewState["Text"] = value; 
      } 
     } 

     protected override void RenderContents(HtmlTextWriter output) 
     { 
      output.Write(Text); 

      string block = "<p>Here is some text.</p>"; 
      output.Write(block);    
     } 
    } 
} 

回答

6

它應該僅僅是:

<cc1:StandardControl ID="scSomething" runat="server"> 
</cc1:StandardControl> 
+1

+1是;在命名空間ServerControlSandbox中沒有控制權,類名爲StandardControl1 - 這就是解析器的工作方式 - 它在所提供的命名空間中指定的程序集中的cc1:前綴後面查找類名 - 我敢打賭,IDE由於某種原因。 – dash 2011-12-16 22:42:48

相關問題