[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Composite Controls and Events

Posted on 2006-04-21
2
Medium Priority
?
656 Views
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
            Get
                Return CStr(ViewState("Title"))
            End Get
            Set(ByVal value As String)
                ViewState("Title") = value
            End Set
        End Property

        Public Property Text() As String
            Get
                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
            Controls.Add(m_label)

            ' 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
            Controls.Add(m_textBox)
        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?
0
Comment
Question by:g-spot
2 Comments
 

Author Comment

by:g-spot
ID: 16511497
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
0
 

Accepted Solution

by:
EE_AutoDeleter earned 0 total points
ID: 16678632
g-spot,
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.

EE_AutoDeleter
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Screencast - Getting to Know the Pipeline
Suggested Courses

825 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