Custom Control RaiseEvent

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adam

    #1

    Custom Control RaiseEvent

    I cannot figure out what I'm doing wrong, can someone shed some light on
    this for me?

    I have the following code inside a working user control (MyControl):

    Public Event SubmitClick(ByV al sender As Object, ByVal e As EventArgs)
    Private Sub btnSubmit_Click (ByVal sender As Object, ByVal e As
    System.EventArg s) Handles btnSubmit.Click

    RaiseEvent SubmitClick(sen der, e)

    End Sub

    In the code-behind of the calling page I have this:

    Protected WithEvents ctrlMyControl As MyControl
    Private Sub ctrlMyControl_S ubmitClick(ByVa l sender As Object, ByVal e As
    System.EventArg s) Handles ctrlMyControl.S ubmitClick

    End Sub

    When I run it through the debugger, the RaiseEvent line fires, but none of
    the code in the code-behind runs.

    Thanks in advance for any assistance you can lend!



  • expertware@libero.it

    #2
    Re: Custom Control RaiseEvent


    Make sure the instance of MyControl which is raising the event is in
    the same place where you have placed the handler.

    -Pamela
    ..NET Developer


    ps
    probably the full code would make more clear what you are doing. In
    case, try also declaring the event as SHARED to see
    if it is a scope problem.

    Comment

    • Adam

      #3
      Re: Custom Control RaiseEvent

      Thank you for the asssitance.
      I have found some additional information.

      I am currently using the custom control in the EditItemTemplat e of a
      datalist. When I pull the control out of the datalist, the events fire
      perfectly.
      What am I missing in order to wire up the events when using it in the
      EditItemTemplat e.

      I tried adding this code to the EditCommand routine:

      AddHandler MyControl.Submi tClick, AddressOf ctrlMyControl_S ubmitClick

      But received an "object not set to an instance" error.
      Thanks again for any assistance!


      Comment

      • expertware@libero.it

        #4
        Re: Custom Control RaiseEvent

        Check if you have a duplicate construction
        something like:

        dim withevents Control as new control
        control = new control

        so that the instance which you are passing the delegate
        is not the same which is used later on ...


        -Pamela
        ..NET Developer


        Comment

        Working...