Custom ASP.NET Control Analysis (1)

zhaozj2021-02-16  74

JXF_YX

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. ")> Public Class WebcustomControl1

4. Inherits System.Web.ui.WebControls.WebControl

5. DIM _Text As String

6. Property [Text] () AS String

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> ")

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 {0}: The corresponding name. For example, you change the class WebcustomControl1 to WebCustom.

The ToolboxData ("<{0}: WebcuStomControl1 Runat = Server> " is required. ) Otherwise, it will be wrong 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

The property is applied to illustrating the BrowSableAttribute property and event specifying attributes or events should be displayed in the property browser. The categoryAttribute property and event specify the name of the category, and the attributes or events will be packet in this category. When the category is used, the component properties and events can be displayed in the Properties Browser by logical packet. DescriptionAttribute properties 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. The BindableAttribute property specifies whether you want to bind to this property. DEFAULTPROPERTYATTRIBUTE attribute

(Insert this feature into the class declaration.) Specify the default properties of the component. This property will be selected in the Properties Browser when the user clicks the control. The DefaultValueAttribute property sets a simple default value for the property. The EditoAttribute property specifies the editor to use when editing (changes) properties in the Visual Designer. The localizableAttribute property specifies that the 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. The DesignerIzationVisibilityAttribute property specifies whether the properties displayed in the Properties browser should be (and how) permanently reside in the code. The TypeConvertRIBUTE property specifies the type converter to use when converting the type of the property to another data type. DefaulTeventAttribute event

(Insert this feature into the 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

转载请注明原文地址:https://www.9cbs.com/read-15164.html

New Post(0)