Composite Controls and Events

Posted on 2006-04-21
Last Modified: 2010-05-18
I've created a composite control with a TextChanged event on the TextBox child control:

Namespace myControls

    Public Class TitledTextBox

        Inherits CompositeControl

        Private m_label As Label
        Private m_textBox As TextBox

        Public Property Title() As String
                Return CStr(ViewState("Title"))
            End Get
            Set(ByVal value As String)
                ViewState("Title") = value
            End Set
        End Property

        Public Property Text() As String
                Return CStr(ViewState("Text"))
            End Get
            Set(ByVal value As String)
                ViewState("Text") = value
            End Set
        End Property

        Protected Overrides Sub CreateChildControls()
            ' Add The Label
            m_label = New Label()
            m_label.EnableViewState = False
            m_label.Text = Title

            ' Add a Space
            Controls.Add(New LiteralControl("  "))

            ' Add the text box
            m_textBox = New TextBox()
            m_textBox.EnableViewState = False
            m_textBox.Text = Text
            AddHandler m_textBox.TextChanged, AddressOf OnTextChanged
        End Sub

        Public Event TextChanged As EventHandler

        Protected Overridable Sub OnTextChanged(ByVal sender As Object, ByVal e As EventArgs)
            If TextChangedEvent IsNot Nothing Then
                RaiseEvent TextChanged(Me, e)
            End If
        End Sub

    End Class
End Namespace

How do I "get at" that event. This code doesnt work:

    Sub textchanged() Handles myNewControl.TextChanged

        Label1.Text = myNewControl.Text & " - this has changed"

    End Sub

I get the following error:

BC31029: Method 'Public Sub textchanged()' cannot handle Event 'Public Event TextChanged(sender As Object, e As System.EventArgs)' because they do not have the same signature.

What is going wrong?
Question by:g-spot

    Author Comment

    The problem was that I missed the paramters from the textchanged routine. Should be:

    Sub textchanged(ByVal sender As Object, ByVal e As EventArgs)

        Sub textchanged(ByVal sender As Object, ByVal e As EventArgs) Handles myNewControl.TextChanged

            Label1.Text = myNewControl.Text & " - this has changed"

        End Sub

    Accepted Solution

    Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now