ConstructorNeedsTagAttribute Constructor (Boolean)

 

Initializes a new instance of the ConstructorNeedsTagAttribute class.

Namespace:   System.Web.UI
Assembly:  System.Web (in System.Web.dll)

Public Sub New (
	needsTag As Boolean
)

Parameters

needsTag
Type: System.Boolean

true to add a tag to a control; otherwise, false.

The following code example creates a simple custom control whose tag name is defined at run time. The following is the command line used to build the executable.

vbc /r:System.dll /r:System.Web.dll /t:library /out:myWebAppPath/Bin/vb_myconstructorNeedsTagAtt.dll constructNeedsTagAtt.vb
' File name: constructorneedstagatt.cs. 

Imports System
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 'NewNew

      <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 'Render
   End Class 'Simple
End Namespace 'MyUserControl

The following code example uses the previous custom control. Notice that the values shown in the Register directive reflect the previous command line.

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

.NET Framework
Available since 1.1
Return to top
Show: