Aracılığıyla paylaş


ConstructorNeedsTagAttribute Oluşturucular

Tanım

ConstructorNeedsTagAttribute sınıfının yeni bir örneğini başlatır.

Aşırı Yüklemeler

ConstructorNeedsTagAttribute()

ConstructorNeedsTagAttribute sınıfının yeni bir örneğini başlatır.

ConstructorNeedsTagAttribute(Boolean)

ConstructorNeedsTagAttribute sınıfının yeni bir örneğini başlatır.

ConstructorNeedsTagAttribute()

ConstructorNeedsTagAttribute sınıfının yeni bir örneğini başlatır.

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

Örnekler

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

Ayrıca bkz.

Şunlara uygulanır

ConstructorNeedsTagAttribute(Boolean)

ConstructorNeedsTagAttribute sınıfının yeni bir örneğini başlatır.

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

Parametreler

needsTag
Boolean

true bir denetime etiket eklemek için; aksi takdirde , false.

Örnekler

Aşağıdaki kod örneği, etiket adı çalışma zamanında tanımlanan basit bir özel denetim oluşturur. Aşağıda yürütülebilir dosyayı oluşturmak için kullanılan komut satırı yer alır.

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

Aşağıdaki kod örneği önceki özel denetimi kullanır. yönergesinde gösterilen değerlerin Register önceki komut satırını yansıttığını göreceksiniz.

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

Şunlara uygulanır