Media Player and flash plug-in controls executed on Web pages are ActiveX controls which are applied in HTML code in similar ways, except for specifying classid, activeX parameters (equivalent to ActiveX control attributes) are represented by Param tags. The title of this article is "ActiveX Server Control" to avoid misunderstanding as ActiveX control, but in ASP. the server control that outputs ActiveX-related html codes. The ActiveX Server control can be used to output the common HTML code that references ActiveX on a webpage. In addition, ActiveX parameters are displayed as set attributes, therefore, we will also learn how to write set attributes.
ProgramCodeDownload: ASP. NET Server Control-day11.rar
I. Set attributes
The param parameter of ActiveX is a set attribute. Therefore, we define the tbactiveparam class description ActiveX parameter, which includes the name and value Attributes. The tbactivexparamcollection is a set category of tbactiveparam and is used to describe the ActiveX parameter set. Tbactivexparamcollection inherits collectionbase and adds add, insert, remove, indexof, and contains methods to the operation set, for details about the usage of set attributes, refer to the article "collectionbase of server controls" in the blog.
II. Implementation ActiveXServer Control
Step1.New inheritance WebcontrolOf Tbactivex
Step2.Overwrite TagkeyProperty, return ObjectOf Tag
Protected Overrides Readonly PropertyTagkey ()AsHtmltextwritertag
Get
ReturnHtmltextwritertag.Object
End Get
EndProperty
Step3.New ClassidAttribute, description ActiveXOf Classid.
Define the classid attribute and overwrite the addattributestorender to output this attribute.
''' <Summary>
''' Override the uploaddattributestorender method.
''' </Summary>
Protected Overrides SubAddattributestorender (ByvalWriterAsHtmltextwriter)
'Add the classid of the mediaplayer ActiveX component
Writer. addattribute ("Classid",String. Format ("CLSID: {0 }",Me. Classid ))
Mybase. Addattributestorender (writer)
EndSub
Step 4.NewParamsAttribute, description ActiveX.
Define the Params attribute. The type is tbactivexparamcollection type. Use editorattribute to set collectioneditor as the collection editor.
''' <Summary>
''' ActiveX controls the dataset data set.
''' </Summary>
<_
Description ("Controls the dataset data set. "),_
Persistencemode (persistencemode. innerproperty ),_
Designerserializationvisibility (designerserializationvisibility. content ),_
Editor (GetType(Collectioneditor ),GetType(Uitypeeditor ))_
> _
Public Readonly PropertyParams ()AsTbactivexparamcollection
Get
IfFparamsIs Nothing Then
Fparams =NewTbactivexparamcollection ()
End If
ReturnFparams
End Get
EndProperty
When editing Params, The collectioneditor Set editor is used.
Step5.Output ActiveXParameters
Override the createchildcontrols method. This method outputs the ActiveX parameter set in sequence according to the Params set attribute definition.
Private SubAddparam (ByvalNameAs String,ByvalValueAs String)
DimOparamAsHtmlcontrols. htmlgenericcontrol
Oparam =NewHtmlcontrols. htmlgenericcontrol ("Param")
Oparam. Attributes. Add ("Name", Name)
Oparam. Attributes. Add ("Value", Value)
Me. Controls. Add (oparam)
End Sub
''' <Summary>
''' Create a subcontrol worker.
''' </Summary>
Protected Overrides SubCreatechildcontrols ()
DimOparamAsTbactivexparam
'Add to ActiveX metric data set
For EachOparamIn Me. Params
Addparam (oparam. Name, oparam. value)
Next
Mybase. Createchildcontrols ()
EndSub
Iii. execution procedure
In the previous article, we used the tbmediaplayer control to set the Media Player. Here we use the tbactivex control to set the media player, and the same results can be displayed.
<Bee: tbactivex ID= "Tbactivex1" Runat= "Server"
Classid= "6bf52a52-394a-11d3-b153-00c04f79faa6" Height= "250px" Width= "250px">
<Params>
<Bee: tbactivexparam Name= "Url" Value= "D:/movie_01.wmv" />
<Bee: tbactivexparam Name= "Autostart" Value= "True" />
</Params>
</Bee: tbactivex>
Note: This article is also published in "the first it state help tie Ren Competition". If you think this articleArticleIt is helpful to you. Remember to add popularity when you connect to this article ^
Http://ithelp.ithome.com.tw/question/10012159