How do you setup AddHandler on a parent form for a usercontrol event that is nested within a gridview?

I am trying to call a function using delegates in a parent form using AddHandler when a button click event is fired within a usercontrol that is on the form.

I have built a test application where I can get this working. The class on the parent form is:

Partial Class _Default
    Inherits System.Web.UI.Page
    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        AddHandler WebUserControl1.btnHandler, AddressOf test
    End Sub

    Public Sub test(ByVal strVacancyID As String)
       Response.Write("Called From TEST: " + strVacancyID)
    End Sub
End Class

The class on the User Control is:

Partial Class usercontrol_WebUserControl
    Inherits System.Web.UI.UserControl

    Public Delegate Sub OnButtonClick(ByVal strVacancyID As String)

    Public Event btnHandler As OnButtonClick

    Protected Sub btnTest_Click(ByVal sender As Object, ByVal e As EventArgs)
        RaiseEvent btnHandler("87")
    End Sub
End Class

However, in my current project the user control is nested within a gridview, when I try to add the "AddHandler" code the form can't "see" the user control, presumably because it is nested within the gridview.

How can I link the nested usercontrol to the AddHandler?

Many thanks,
robert_rawAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vb_jonasCommented:
Hi, you need to add the reference within the usercontrol tag:
<uc1:WebUserControl ID="WebUserControl1" runat="server" OnbtnHandler="test"/>

OnbtnHandler should appear in intellisense.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
robert_rawAuthor Commented:
Hi vb jonas,
Thanks for the solution it works perfectly. I would never have figured that out myself. Thanks very much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.