Custom ASP.NET Control Analysis (1)
A few days ago, I did several controls. I want to write my own understanding of the custom control, please express my experience in custom controls.
Let us make better handles to make the controls you need.
The template for automatically generated by .NET is explained below. (As an example of VB language)
1. IMPORTS System.comPonentModel
2.imports system.Web.ui
3.
4. Inherits System.Web.ui.WebControls.WebControl
5. DIM _Text As String
6.
7. Get
8. Return_Text
9. End Get
10. SET (ByVal Value As String)
11. _Text = Value
12. End Set
13. End Property
14. Protected Overrides Sub Render (Byval Output As System.Web.ui.htmlTextWriter)
15. Output.write ([Text])
16. End Sub
17.END CLASS
'------------------------------------- ----------------
'1-2 Import Namespace, System.comPonentmodel and System.Web.ui have nothing to introduce
'3 DefaultProperty ("text") - Specifies the default value of the property. If you use this property, you need to import (namespace: system.componentmodel)
ToolboxData ("<{0}: WebcustomControl1 Runat = Server> {0}: WebcustomControl1>")
Specifies the default tag that it generates when the custom control is dragged from the toolbox from Tools such as Visual Studio.
In the following example, set a number of attributes specific to MYLabel. All matching items of {0} are replaced by the designer to a tag prefix associated with MyLabel class.
Public Class WebcustomControl1 defines a class named WebcustomControl1, and later compiles the generated DLL named WebcustomTrol1
(Note: If you modify the class name. You need to modify the {0}: The corresponding name. For example, you change the class WebcustomControl1 to Webcustom. You need to put ToolboxData ("<{0}: WebcustomControl1 runat = Server> < / {0}: WebcustomControl1> ") changed
ToolboxData ("<{0}: Webcustom Runat = Server> {0}: WebcuStom>") Otherwise, it will be erroneous after compiling. )
'4 inherits indicates inheritance. Here is how to inherit system.web.ui.webcontrols.webcontrol, attributes, events, etc.
'6 This sentence is mainly to control the display of custom controls in the' Properties Browser ', first explain the sentence of the template, and expand the opening
Property [Text] () AS String Definition Text Attribute is a string type
Bindable (TRUE) Specifies whether to bind to this property. -True is that False is not
Category ("APPEARANCE") --Text property will appear in the appearance group. The name of the specified category will group attributes or events in this category. When the category is used, the component properties and events can be displayed in the Properties Browser by logical packet.
DEFAULTVALUE ("") Sets a simple default value for the property. Here is empty
All of the features are listed below
Details can be viewed in MS-Help: //ms.vscc/ms.msdnvs.2052/cpguide/html/cpcondesign-timeattributesForComponents.htm
Attributes
Use
Description
BrowsableamTribute
Attributes and events
Specifies whether an attribute or event should be displayed in the property browser.
CategoryAttribute
Attributes and events
The name of the specified category will group attributes or events in this category. When the category is used, the component properties and events can be displayed in the Properties Browser by logical packet.
DescriptionAttribute, DESCRIPTIONATTRIBUTE
Attributes and events
Define a small piece of text that will be displayed at the bottom of the property browser when the user selects attributes or events.
BindableAttribute
Attributes
Specifies whether to bind to this property.
DefaultPropertyAttribute
Attributes (before inserting this feature into class declaration.) Specify the default properties of the component. This property will be selected in the Properties Browser when the user clicks the control.
DefaultValueAttribute
Attributes
Set a simple default value for the property.
EditoAttribute
Attributes
Specifies the editor to use when editing (changes) properties in a visual designer.
LocalizableamTribute
Attributes
Specifying properties should be localized. When a user is to localize a form, any properties with this feature will automatically be free to stay in the resource file.
DesignerSerizationVisibilityAttribute
Attributes
Specifies whether the attribute displayed in the property browser should be (and how) permanently reside in the code.
TypeConverTeratTribute
Attributes
Specifies the type converter to be used when converting the type of attribute to another data type.
DefaultEventAttribute
Event (insert this feature into class declaration.) Specify the default event of the component. This is the event selected in the property browser when the user clicks on the component.
The .NET also supports custom features, this will not be said, interested can check the MSDN, which has a detailed description
Refer to MS-Help: //ms.vscc/ms.msdnvs.2052/cpguide/html/cpconwritingcustomattributes.htm
7-12 is very simple, meaning returns the value of the (GET) TEXT attribute and setting (SET) TEXT attribute value
13 TEXT attribute
14-16 This process is to rewrite the presence of the control. Here is the value of displaying the TEXT attribute on the page
Here is just a brief introduction to custom controls. I will use the example to specifically introduce the properties, methods, events in the custom control.