2011-12-16 55 views
4

これは、ASP.NETサーバーコントロールを構築する私の最初の試みです。コントロールコードを書くことは簡単でしたが、私はロードブロッキングを実行してWebページのコントロールを取得しようとしました。ASP.NETサーバーコントロールエラー:不明なサーバータグ

コントロールを1つのプロジェクトに作成し、別のプロジェクトで参照しました。その2番目のプロジェクトでは、私はツールボックスのコントロールを取得し、ページ上のコントロールをドラッグ/ドロップしました。私は、エラーなしで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ファイルに追加すると述べました。私は、私が行方不明ですが、私は私が見てきた例から判断すると、間違って何も見えないシンプルなものがあると思ってい

<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> 

:しかし、私のweb.configファイルでこれを私はまだエラーを取得します。誰にもアイデアはありますか?ありがとう。また、ここでは制御コードは

されています:

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:プレフィックスの後にclassnameを探します。何らかの理由で。 – dash

+0

説明のおかげで@ダッシュ:) –

+0

それはトリックをした - はい、彼らは 'StandardControl1'は、IDEによってドロップされた。私は長い間その壁を探して壁を叩いていただろう。ありがとう! –