예, 당신은 그것을 할 수 있습니다 ... 상속을 사용하고
1 먼저 재정을 CreateChildControls 방법의 예와는 WebPart 클래스에서 상속 기본 클래스를 만들려면 다음과 같이 기본 클래스를 작성하여
<XmlRoot("MyWebPartBase")> _
<ToolboxItemAttribute(True)> _
Public Class BaseWebPart
Inherits WebPart
Protected Overrides Sub CreateChildControls()
Dim control As Object = Page.LoadControl(ascxPath)
If control IsNot Nothing Then
control.WebPartControl = Me
Controls.Add(CType(control, Control))
End If
End Sub
'Add public properties here
End Class
2 -이 기본 클래스에서 속성을 구현하고 webpart 클래스 대신 위에서 언급 한 기본 클래스의 webparts를 고유합니다.
3 사용자 정의 컨트롤에 액세스하기 위해 공용 속성을 구현하는 사용자 정의 컨트롤에 대한 기본 클래스를 만듭니다.
Public Class BaseUserControl
Inherits UserControl
Private _WebPartControl As BaseWebPart
Public Property WebPartControl As BaseWebPart
Get
Return _WebPartControl
End Get
Set(ByVal value As BaseWebPart)
_WebPartControl = value
End Set
End Property
Public ReadOnly Property WebPartID() As String
Get
Return WebPartControl.ID
End Get
End Property
End Class