Click here to Skip to main content
16,018,525 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,

I have a user control in which I have a drop down. I want to handle the selected index change of this drop down in my parent page. I tried with some test application and I was succesfull to capture the click of a button using events and delegates, however that was in C#.
Now I need to do the same but in VB.net plus the control is drop down instead of button in user control.
I succeeded so far for creating my events and delegates however, I am not able to see the handler accociated with my user control's drop down in the intellisense which i will make use for capturing the event. Here is my code for my User Control :
VB
Public Delegate Sub IndexChangedEventHandler(strValue As String)
    Public Event IndexChanged As EventHandler

    Protected Sub ddlTemp_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlTemp.SelectedIndexChanged
        Dim str As String
        str = ddlTemp.SelectedItem.Text 
        RaiseEvent IndexChanged(Me, New EventArgs())
    End Sub 


Here is my Parent page code behind
VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

        uc1.IndexChanged += New WebUserControl1.IndexChangedEventHandler(hndle_index)

    End Sub

    Sub hndle_index(ByVal str As String)
        Response.Write(str)
    End Sub
.

I am getting these errors and I am not sure how to proceed:
1.
VB
Error   1   'Public Event IndexChanged(strValue As String)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event. D:\Taresh\POCS\ucInvokingVB\ucInvokingVB\Default.aspx.vb    6   9   ucInvokingVB

2.
VB
Error   2   Delegate 'ucInvokingVB.WebUserControl1.IndexChangedEventHandler' requires an 'AddressOf' expression or lambda expression as the only argument to its constructor.   D:\Taresh\POCS\ucInvokingVB\ucInvokingVB\Default.aspx.vb    6   74  ucInvokingVB



Please Help ! Thanx a lot !
Posted

1 solution

can you try like below to invoke your dropdown changed event in parent page

this is how your user control code look likes

VB
Public Delegate Sub IndexChangedEventHandler(strValue As String)
    Public Event IndexChanged As EventHandler

    Protected Sub ddlTemp_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlTemp.SelectedIndexChanged
        Dim str As String
        str = ddlTemp.SelectedItem.Text
//Changed Line of Code
        RaiseEvent IndexChanged()
    End Sub


and try this line of code in your parent control

protected sub HandleEvent() handles uc1.IndexChanged

//Put your code here

End Sub
 
Share this answer
 
Comments
Member 11698981 4-Jun-15 6:14am    
Thanx a lot !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900