ConstructorNeedsTagAttribute 생성자

정의

ConstructorNeedsTagAttribute 클래스의 새 인스턴스를 초기화합니다.

오버로드

ConstructorNeedsTagAttribute()

ConstructorNeedsTagAttribute 클래스의 새 인스턴스를 초기화합니다.

ConstructorNeedsTagAttribute(Boolean)

ConstructorNeedsTagAttribute 클래스의 새 인스턴스를 초기화합니다.

ConstructorNeedsTagAttribute()

ConstructorNeedsTagAttribute 클래스의 새 인스턴스를 초기화합니다.

public:
 ConstructorNeedsTagAttribute();
public ConstructorNeedsTagAttribute ();
Public Sub New ()

예제

 // Attach the ConstructorNeedsTagAttribute to the custom
 // SimpleControl, which is derived from WebControl. When
 // this version of the constructor is used, the NeedsTag
 // property is automatically set to false; therefore,
 // this class does not need a tag attribute.
 [ConstructorNeedsTagAttribute()] 
 [AspNetHostingPermission(SecurityAction.Demand, 
     Level=AspNetHostingPermissionLevel.Minimal)]
 public sealed class SimpleControl : WebControl 
 {
 
      private String UserMessage=null;
 
      // Create a property named ControlValue.
      public String ControlValue 
      {
         get 
         {
            return UserMessage;
         }
         set 
         {
            UserMessage = value;
         }
       }
             
      protected override void Render(HtmlTextWriter output) 
      {
        output.Write("Testing the ConstructorNeedsTagAttribute class.");
     }
}
' Attach the ConstructorNeedsTagAttribute to the custom
' SimpleControl, which is derived from WebControl. When
' this version of the constructor is used, the NeedsTag
' property is automatically set to false; therefore,
' this class does not need a tag attribute.
<ConstructorNeedsTagAttribute()>  _
<AspNetHostingPermission(SecurityAction.Demand, _
   Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class SimpleControl
   Inherits WebControl
   
   Private UserMessage As [String] = Nothing
   
   ' Create a property named ControlValue.
   
   Public Property ControlValue() As [String]
      Get
         Return UserMessage
      End Get
      Set
         UserMessage = value
      End Set
   End Property
   
   
   Protected Overrides Sub Render(output As HtmlTextWriter)
      output.Write("Testing the ConstructorNeedsTagAttribute class.")
   End Sub
 End Class

추가 정보

적용 대상

ConstructorNeedsTagAttribute(Boolean)

ConstructorNeedsTagAttribute 클래스의 새 인스턴스를 초기화합니다.

public:
 ConstructorNeedsTagAttribute(bool needsTag);
public ConstructorNeedsTagAttribute (bool needsTag);
new System.Web.UI.ConstructorNeedsTagAttribute : bool -> System.Web.UI.ConstructorNeedsTagAttribute
Public Sub New (needsTag As Boolean)

매개 변수

needsTag
Boolean

컨트롤에 태그를 추가하면 true이고, 그렇지 않으면 false입니다.

예제

다음 코드 예제에서는 런타임에 태그 이름이 정의 하는 간단한 사용자 지정 컨트롤을 만듭니다. 다음은 명령줄 실행 파일을 빌드하는 데 사용 합니다.

vbc /r:System.dll /r:System.Web.dll /t:library /out:myWebAppPath/Bin/vb_myconstructorNeedsTagAtt.dll constructNeedsTagAtt.vb  
csc /t:library /out:myWebAppPath/Bin/cs_myConstructorNeedsTagAtt.dll constructorNeedsTagAtt.cs  
/* File Name: constructorneedstagatt.cs. */

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace MyUserControl 
{
  // Attach the 'ConstructorNeedsTagAttribute' to 'Simple' class. 
  [ConstructorNeedsTagAttribute(true)]
  public class Simple : WebControl 
  {
    private String NameTag = "";

    public Simple(String tag)
    {
      this.NameTag = tag;
    } 
 
    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
    protected override void Render(HtmlTextWriter output) 
    {
      output.Write("<br>The TagName used for the 'Simple' control is "+"'"+NameTag+"'");
    }
  }  
}
' File name: constructorneedstagatt.cs. 

Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel


Namespace MyUserControl
   <ConstructorNeedsTagAttribute(True)>  _
   Public Class Simple
      Inherits WebControl
      Private NameTag As [String] = ""
      
      Public Sub New(tag As [String])
        Me.NameTag = tag
      End Sub
      
      <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
      Protected Overrides Sub Render(output As HtmlTextWriter)
        output.Write(("<br>The TagName used for the 'Simple' control is " + "'" + NameTag + "'"))
      End Sub
   End Class
End Namespace 'MyUserControl

다음 코드 예제에서는 이전 사용자 지정 컨트롤을 사용 합니다. 에 표시 된 값을 확인 하는 Register 지시문 이전 명령줄을 반영 합니다.

<%@ Register TagPrefix='MyCurrentUserControl' Namespace='MyUserControl' Assembly='vb_myConstructorNeedsTagAtt'%>  
 <html>  
  <body>  
  <form method="POST" runat="server">  
  <MyCurrentUserControl:Simple runat="server" />  
  </form>  
  </body>  
 </html>  
<%@ Register TagPrefix='MyCurrentUserControl' Namespace='MyUserControl' Assembly='cs_myConstructorNeedsTagAtt'%>  
 <html>  
  <body>  
  <form method="POST" runat="server">  
  <MyCurrentUserControl:Simple runat="server" />  
  </form>  
  </body>  
 </html>  

적용 대상