Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Web.UI
- Imports System.Web.UI.WebControls
- Public Class LabeledCompositeControl
- Inherits CompositeControl
- Private _panel As Panel
- Protected ReadOnly Property Panel As Panel
- Get
- If _panel Is Nothing Then
- _panel = New Panel()
- End If
- Return _panel
- End Get
- End Property
- Private _label As Label
- Protected ReadOnly Property Label As Label
- Get
- If _label Is Nothing Then
- _label = New Label With {
- .Visible = True
- }
- End If
- Return _label
- End Get
- End Property
- Public Property LabelText As [String]
- Get
- Return Label.Text
- End Get
- Set(value As String)
- Label.Text = value
- End Set
- End Property
- ''' <summary>
- ''' Geeft aan of er een linebreak tussen het label en control geplaatst moet worden.
- ''' </summary>
- ''' <value></value>
- ''' <returns></returns>
- ''' <remarks>Default waarde is False</remarks>
- Public Property RenderBreak As Boolean
- Get
- Return (If(ViewState("RenderBreak") Is Nothing, False, CBool(ViewState("RenderBreak"))))
- End Get
- Set(value As Boolean)
- ViewState("RenderBreak") = value
- End Set
- End Property
- Protected Overridable Sub SetAssociatedControlID(ByRef AssociatedControlID As String)
- End Sub
- Public Overrides ReadOnly Property Controls As ControlCollection
- Get
- Return Panel.Controls
- End Get
- End Property
- Protected Overrides Sub CreateChildControls()
- CssClass = "labeledcontrol"
- Label.CssClass = "label"
- Dim associatedControlID As String = ""
- SetAssociatedControlID(associatedControlID)
- If Not String.IsNullOrEmpty(associatedControlID) Then
- Label.AssociatedControlID = associatedControlID
- End If
- Panel.Controls.Add(Label)
- If RenderBreak Then
- Panel.Controls.Add(New Literal With {.Text = "<br />"})
- End If
- MyBase.Controls.Add(Panel)
- End Sub
- ''' <summary>
- ''' Needed for validators trying to find controls outside their namingcontainer
- ''' http://www.michaelkbell.com/index.php/2009/04/21/validation-against-controls-outside-of-the-current-namingcontainer/
- ''' </summary>
- ''' <param name="id"></param>
- ''' <param name="pathOffset"></param>
- ''' <returns></returns>
- Protected Overrides Function FindControl(id As String, pathOffset As Integer) As Control
- ' try to find the control the "normal" way
- Dim c As Control = MyBase.FindControl(id, pathOffset)
- If c IsNot Nothing Then
- Return c
- End If
- ' if it wasn't found try the "other" way ...
- Return FindControl(Page, id)
- End Function
- ''' <summary>
- ''' Recursively find a control based on its ID and start searching at "my" parent's controls
- ''' </summary>
- ''' <param name="parent"></param>
- ''' <param name="id"></param>
- ''' <returns></returns>
- Public Overloads Function FindControl(parent As Control, id As String) As Control
- Dim recurse As Control
- If parent.ID = id Then
- Return parent
- End If
- For Each child As Control In parent.Controls
- recurse = FindControl(child, id)
- If recurse IsNot Nothing Then
- Return recurse
- End If
- Next
- Return Nothing
- End Function
- End Class
- Public Class LabeledTextBox
- Inherits LabeledCompositeControl
- Private _textBox As TextBox
- Public Property [Mode] As String
- Set(value As String)
- Select Case value
- Case "MultiLine"
- TextBox.TextMode = TextBoxMode.MultiLine
- Exit Select
- Case Else
- TextBox.TextMode = TextBoxMode.SingleLine
- Exit Select
- End Select
- End Set
- Get
- Return TextBox.TextMode.ToString()
- End Get
- End Property
- Public Property Rows As Integer
- Set(value As Integer)
- TextBox.Rows = value
- End Set
- Get
- Return TextBox.Rows
- End Get
- End Property
- Public Property Columns As Integer
- Set(value As Integer)
- TextBox.Columns = value
- End Set
- Get
- Return TextBox.Columns
- End Get
- End Property
- Public Property EnteredText As String
- Set(value As String)
- TextBox.Text = value
- End Set
- Get
- Return TextBox.Text
- End Get
- End Property
- Protected Overrides Sub SetAssociatedControlID(ByRef AssociatedControlID As String)
- AssociatedControlID = TextBox.ID
- End Sub
- Public ReadOnly Property TextBox As TextBox
- Get
- If _textBox Is Nothing Then
- _textBox = New TextBox() With {
- .ID = "txtTextbox",
- .Visible = True
- }
- End If
- Return _textBox
- End Get
- End Property
- Public Property [ReadOnly] As Boolean
- Set(value As Boolean)
- TextBox.[ReadOnly] = value
- End Set
- Get
- Return TextBox.[ReadOnly]
- End Get
- End Property
- Public Property MaxLength As Integer
- Set(value As Integer)
- TextBox.MaxLength = value
- End Set
- Get
- Return TextBox.MaxLength
- End Get
- End Property
- Protected Overrides Sub CreateChildControls()
- MyBase.CreateChildControls()
- TextBox.Width = Width
- TextBox.CssClass = "textbox"
- Controls.Add(TextBox)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement