http://blog.9cbs.net/21ASPNET/Archive/2004/10/24/149763.aspx
http://blog.9cbs.net/21ASPNET/Archive/2004/10/24/149763.aspx
Custom ASP.NET control analysis
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
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. The defaultpropertyattribute property (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 (before inserting this feature into class declaration.) Specify the default event for 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 (GET) TEXT attribute value and setting (SET) TEXT attribute's value 13 Text attribute end
14-16 This process is to rewrite the presence of the control. Here is the value of displaying the TEXT attribute on the page
In ASP.NET, when you want to confirm your confirmation of Button's Click event, but the Button button cannot meet this requirement. It is aimed at this request to write your own control.
============================================================================================================================================================================================================= ====================
Inheritance: System.Web.ui.WebControls.Button
Control function: pop-up confirmation message box
Control Properties: Message (information displayed in the Message box)
Control method: no need
Control event: no need
How to use: "OK" The Button_Click event of the execution button, "Cancel" does not perform any events.
Imports system.componentmodel
Imports System.Web.ui
Namespace WebControls
'Inheriting button
Inherits System.Web.ui.WebControls.Button
'Provide unique namespace for any server control included
Implements inamingcontainer
DIM _MESSAGE AS STRING
'Define the Message properties.
Get
Return_Message
END GET
Set (byval value as string)
_Message = Value
End set
End Property
Public Sub New ()
_Message = ""
End Sub
'Override the output of the control
Protected Overrides Sub Render (Byval Output As System.Web.ui.htmlTextWriter)
'Add a client onclick event for the control.
If Me.Message.trim <> "" "" "", "JScript: if (! Confirm ('" & me.Message & ")) Return False;")
Me.attributes.add ("onfocus", "JScript: this.blur ();") MyBase.Render (Output)
End Sub
END CLASS
End Namespace
============================================================================================================================================================================================================= ====================
Inheritance: System.Web.ui.WebControls.Button
Control function: pop-up confirmation message box
Control Properties: Message (information displayed in the Message box)
Control method: no need
Control event: no need
How to use: "OK" The Button_Click event of the execution button, "Cancel" does not perform any events.
Imports system.componentmodel
Imports System.Web.ui
Namespace WebControls
'Inheriting button
Inherits System.Web.ui.WebControls.Button
'Provide unique namespace for any server control included
Implements inamingcontainer
DIM _MESSAGE AS STRING
'Define the Message properties.
Get
Return_Message
END GET
Set (byval value as string)
_Message = Value
End set
End Property
Public Sub New ()
_Message = ""
End Sub
'Override the output of the control
Protected Overrides Sub Render (Byval Output As System.Web.ui.htmlTextWriter)
'Add a client onclick event for the control.
If Me.Message.trim <> "" "" "", "JScript: if (! Confirm ('" & me.Message & ")) Return False;")
Me.attributes.add ("onfocus", "jscript: this.blur ();")
MyBase.Render (Output)
End Sub
END CLASS
End Namespace