(B) The second method - the user interface, control + implementation IWebPart
Below, we will focus on the second approach - Construction of UserControl style Web Part. We can create an ASP.NET user control and to achieve IWebPart user interface to create a Web Part. Listing 2 shows an implementation of a Web Part class IWebPart interface framework.
List 2 - to achieve IWebPart way to create user interfaces typical Web Part code
Class myWebUserControl
Inherits System.Web.UI.UserControl
Implements IWebPart
Private _CatalogIconImageUrl As String = "images/5PointStar.gif"
Public Property CatalogIconImageUrl () As String Implements
System.Web.UI.WebControls.WebParts.IWebPart.CatalogIconImageUrl
Get
Return _CatalogIconImageUrl
End Get
Set (ByVal value As String)
_CatalogIconImageUrl = Value
End Set
End Property
Description''
Private _Description As String = "Custom Web Part 【】"
Public Property Description () As String Implements
System.Web.UI.WebControls.WebParts.IWebPart.Description
Get
Return _Description
End Get
Set (ByVal value As String)
_Description = Value
End Set
End Property
Subheading''
Private _Subtitle As String = ""
Public ReadOnly Property Subtitle () As String Implements
System.Web.UI.WebControls.WebParts.IWebPart.Subtitle
Get
Return _Subtitle
End Get
End Property
Title''
Private _Title As String = "My Custom Web Part 【】"
Public Property Title () As String Implements
System.Web.UI.WebControls.WebParts.IWebPart.Title
Get
Return _Title
End Get
Set (ByVal value As String)
_Title = Value
End Set
End Property
''TitleIconImageUrl
Private _TitleIconImageUrl As String = "images/5PointStar.gif"
Public Property TitleIconImageUrl () As String Implements
System.Web.UI.WebControls.WebParts.IWebPart.TitleIconImageUrl
Get
Return (_TitleIconImageUrl)
End Get
Set (ByVal value As String)
_TitleIconImageUrl = Value
End Set
End Property
''TitleUrl
Private _TitleUrl As String = "http://www.example.com"
Public Property TitleUrl () As String Implements
System.Web.UI.WebControls.WebParts.IWebPart.TitleUrl
Get
Return _TitleUrl
End Get
Set (ByVal value As String)
_TitleUrl = Value
End Set
End Property
End Class
Next, we need our custom user control to add visual elements. In this example, we will add three text boxes - they stick together and form our custom control; of course, you can use any other ASP.NET control.
【Tips】 Although this is a Web Part, but it essentially is a ASP.NET user control; so, you can achieve in this package to any function you want.
Now, for the control of a user interface for each component - we want the end user at run time to configure them. To this end, we must define the control of a Boolean indicator, used to determine the user's choice whether to display the element.
Thus, each component has the following form appears:
Protected _PropertyONE As Boolean = True
WebDisplayName ("shows that the first content"), _
WebDescription ("the use of the property to show / hide the first item")> _
Public Property PropertyONE () As Boolean
Get
Return _PropertyONE
End Get
Set (ByVal value As Boolean)
_PropertyONE = Value
End Set
End Property
【Note】 where property is marked as "Personalizable". With this system of property, in the modification of the property, the property's status will be automatically saved. In addition, the property was also marked as "WebBrowsable"; This way, we can in a similar PropertyGridEditorPart (the control and AppearanceEditorPart, BehaviorEditorPart, LayoutEditorPart controls and their container control EditorZone together constitute the personalized Web Part Page "five swordsman ") of the designer to modify it.