From ASP.NET Quick Start Tutorial Custom Controls (1)

xiaoxiao2021-03-06  114

Custom controls from ASP.NET Quick Start Tutorial

Directory 1. Generation logic 2 of the control 2. Develop a composite control 3. Processing events 4 in the composite control. Custom event 5 is triggered from the composite control. Maintenance status 6. Develop a custom (non-composite) control 7 for retrace data. Send a client javascrip 'for custom back ------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- -

1. Control generated logic Each control has a controls property inherited from system.web.ui.control. This is a collection attribute indicating the child control (if any) of the control. If the control does not use the PARSECHILDRENATTRIBUTE tag or tagged as Parsechildrenattribute (ChildrenasProperties = false) When the control is used on the page, the ASP.NET page framework will apply the following analysis logic. If the analyzer encounters a nested control in the tag of the control, it will create an instance of a nested control and add them to the control of the controls attribute. The text between the tag is added to LiteralControl. Any other nested elements generate an analyzer error.

EXP '*********************************************************** ************************************************************ SIMPLEINNERCONTENT.ASPX

<% @ Register tagprefix = "simpleControlsamples" Namespace = "SimpleControlsamples"

AskEMBLY = "SimpleControlsamplesVB"%>

My message is in the control tag! ! ! ! '**************************************** *********************************************************** ********* SimpleInnerContent.vb

Option Strict OffImports SystemImports System.WebImports System.Web.UINamespace SimpleControlSamples Public Class SimpleInnerContentVB: Inherits Control Protected Overrides Sub Render (Output As HtmlTextWriter) If HasControls () And TypeOf Controls (0) Is LiteralControl Dim Ctrl As LiteralControl = Controls (0) Output For your message: "& Ctrl.Text &" ") end if End subs end classnd namespace '******************** *********************************************************** *********************** Note: If the custom control is derived from WebControl, it will not have the analysis logic described in the example because WebControl is used ParsechIldrenattribute (ChildrenasProperties = true) tagged this leads to different analytical logic. For more information on Parsechildrenattribute, see the SDK documentation.

'------------------------------------- -------------------------------------------

2. Developing a composite control: You can create new controls by using the class write combination existing controls. Composite control is equivalent to using the user control created using the ASP.NET page syntax. The main difference between the user control and the composite control is that the user control is maintained as a .ascx text file and the composite control is compiled and kept in the program.

The main steps of developing composite controls are:

Rewote the protected CreateChildControls method inherited from Control: To create an instance of a child control and add them to the control collection. If a new instance of the composite control will be created on the page: please implement the System.Web.ui.inamingContainer interface. This is a tag interface that does not have a method. When implemented with a control, the ASP.NET page framework will create a new naming range under this control. This ensures that the child control has a unique ID in the control hierarchy tree. Since the child control will provide rendering logic, do not rewrite the render method. The properties of the synthesized sub-control properties can be disclosed.

EXP

'********************************************************** ********************************************************* COMPSITION1.ASPX

<% @ Register tagprefix = "compositionsamplesamples" namespace = "CompositionsamplesampleControls"

Assembly = "CompositionSampleControlsVB"%>