ASP.NET Tutorial/Custom Controls/Designer attribute

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Adding a Designer attribute to a control class (C#)

   <source lang="csharp">

using System; using System.Collections.Generic; using System.ruponentModel; using System.Text; using System.Web.UI; using System.Web.UI.WebControls; namespace WebControlLibrary1 {

   [DefaultProperty("Text")]
   [ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
   [Designer(typeof(ControlDesigner))]
   public class WebCustomControl1 : WebControl
   {
       private string text;
       [Bindable(true)]
       [Category("Appearance")]
       [DefaultValue("")]
       public string Text
       {
           get
           {
               return text;
           }
           set
           {
               text = value;
           }
       }
       protected override void Render(HtmlTextWriter output)
       {
           output.RenderBeginTag(HtmlTextWriterTag.Input);
           output.RenderEndTag();
       }
   }

}</source>


Adding a Designer attribute to a control class (VB)

   <source lang="csharp">

Imports System.ruponentModel Imports System.Web.UI Imports System.Web.UI.Design Imports System.ruponentModel.Design <DefaultProperty("Text")> _ <ToolboxData("<{0}:[WebCustomControl1] runat=server></{0}:[WebCustomControl1]>")> _ <Designer(GetType(ControlDesigner))> _ Public Class [WebCustomControl1]

   Inherits System.Web.UI.WebControls.WebControl
   Dim _text As String
   <Bindable(True), Category("Appearance"), DefaultValue("")> _
   Property [Text]() As String
       Get
           Return _text
       End Get
       Set(ByVal Value As String)
           _text = Value
       End Set
   End Property
   Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
       output.RenderBeginTag(HtmlTextWriterTag.Input)
       output.RenderEndTag()
   End Sub

End Class</source>