A little experience in the development of composite control

xiaoxiao2021-03-06  68

For a composite control, its properties are generally the properties of the commissioned sub-control. But sometimes we need to expose a lot of properties of the child control. If there is no good classification management, it will be confusing in the property browser. I am in the actual development process is saved as an attribute as a property. The implementation method is as follows: First, my composite control has a DataGrid, two button, a TextBox. Composite Control (CompositeControl) inherits to WebControl and creates a Builder class and Designer class for it. Builder class:

Public

OVERRIDES

FUNCTION

GetIldControlType

BYVAL

TAGNAME

AS

String

,

BYVAL

Attribs

AS

YSTEM.COLLECTIONS.IDICTIONARY

AS

System.Type

IF

Tagname.tolower (). Endswith (

"

Textbox

"

)

THEN

Return

Gettype

(TextBox)

End

IF

IF

Tagname.tolower (). Endswith (

"

DataGrid

"

)

THEN

Return

Gettype

(DataGrid)

End

IF

IF

Tagname.tolower (). Endswith (

"

Button

"

)

THEN

Return

Gettype

(Button)

End

IF

Return

Nothing

END FUNCTION

Designer class:

Public

OVERRIDES

FUNCTION

GetPersistinnerHTML ()

AS

String

DIM

Strwriter

AS

StringWriter

DIM

HTMLWRITER

AS

HtmlTextWriter

DIM

CONTROL

AS

PressListbox strwriter

=

New

StringWriter HTMLWRITER

=

New

HtmlTextWriter (strwriter) Control

=

Ctype

(

ME

.Component, CompositeControl

Mybase

.GetPersistInnerHtml () htmlWriter.Write (ControlPersister.PersistControl (control.TextBox)) htmlWriter.Write (ControlPersister.PersistControl (control.DataGrid)) htmlWriter.Write (ControlPersister.PersistControl (control.NextButton)) htmlWriter.Write (ControlPersister.PersistControl Control.PreviousButton))

Return

Strwriter.toString

END FUNCTION

Composite control properties:

<

PersistenceMode (PersistenceMode.innerProperty), NotifyParentProperty

True

), _ Description

"

Page Count

"

), Category

"

ChildControl

"

)

>

_

Readonly

Property

PageTextBox ()

AS

TextBoxGet

ME

.EnsurechildControls ()

Return

TXTPAGECUNT

End

Get

End Property

<

PersistenceMode (PersistenceMode.innerProperty), NotifyParentProperty

True

), _ Description

"

DisplayData

"

), Category

"

ChildControl

"

)

>

_

Readonly

Property

PageDataGrid ()

AS

NotifyDataGrid

Get

ME

.EnsurechildControls ()

Return

DGDList

End

Get

End Property

<

PersistenceMode (Persistencemode.innerProperty), Category

"

ChildControl

"

), _ Description

"

"<"

"

), _ NotifyParentProperty

True

)

>

Readonly

Property

PreviouspageButton ()

AS

Button

Get

ME

.EnsurechildControls ()

Return

BtnpRevious

End

Get

End Property

<

PersistenceMode (Persistencemode.innerProperty), Category

"

ChildControl

"

), _ Description

"

">"

"

), _ NotifyParentProperty

True

)

>

Readonly

Property

NextPageButton ()

AS

Button

Get

ME

.EnsurechildControls ()

Return

btnnext

End

Get

End Property

At the same time, the AddPARSUBOBJECT method is also overloaded:

Protected

OVERRIDES

Sub

AddParsedSubObject (

BYVAL

Obj

AS

Object

)

DIM

IDNAME

AS

Array

IF

Typeof

(OBJ)

IS

Textbox

THEN

ME

.txtPageCount

=

Obj

End

IF

IF

Typeof

(OBJ)

IS

DataGrid

THEN

ME

.dgdlist

=

Obj

End

IF

IF

Typeof

(OBJ)

IS

Button

THEN

IDNAME

=

Split

(

Ctype

(Obj, Button) .id.toString,

"

_

"

)

IF

IDNAME

1

) .Tostring.equals

"

NextPageButton

"

)

THEN

ME

.btnnext

=

Obj

Else

ME

.btnprevious

=

Obj

End

IF

End

IF

End Sub

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

New Post(0)