Imports Microsoft.VisualBasic
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts

Namespace Wrox.ConnectionManagement
    Public Class TextBoxChanger
        Inherits WebPart
        Implements IStringForCalendar

        Private myTextBox As TextBox
        Private _calendarString As String = String.Empty

        <Personalizable()> _
        Public Property CalendarString() As String Implements _
          Wrox.ConnectionManagement.IStringForCalendar.CalendarString

            Get
                Return _calendarString
            End Get
            Set(ByVal value As String)
                _calendarString = value
            End Set

        End Property

        <ConnectionProvider("Provider for String From TextBox", _
            "TextBoxStringProvider")> _
        Public Function TextBoxStringProvider() As IStringForCalendar
            Return Me
        End Function

        Protected Overrides Sub CreateChildControls()
            Controls.Clear()
            myTextBox = New TextBox()
            Me.Controls.Add(myTextBox)
            Dim myButton As Button = New Button()
            myButton.Text = "Change Calendar Caption"
            AddHandler myButton.Click, AddressOf Me.myButton_Click
            Me.Controls.Add(myButton)
        End Sub

        Private Sub myButton_Click(ByVal sender As Object, ByVal e As EventArgs)
            If myTextBox.Text <> String.Empty Then
                CalendarString = myTextBox.Text
                myTextBox.Text = String.Empty
            End If
        End Sub
    End Class
End Namespace
