Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handles clause requires a WithEvents variable defined in the containing type or one of its base types

Tags:

asp.net

vb.net

Protected Sub drp_usertype_SelectedIndexChanged(ByVal sender As Object, _
         ByVal e As System.EventArgs) Handles drp_usertype.SelectedIndexChanged

End Sub

getting error under drp_usertype.SelectedINdexChanged

Its a dropdownlist

like image 566
V Partap Singh Salathia Avatar asked Dec 26 '22 06:12

V Partap Singh Salathia


1 Answers

When you declare the drp_usertype object it must be done as :

Private WithEvents drp_usertype As DropDownList

This is the same for

Private WithEvents drp_usertype As New DropDownList

etc...

The WithEvents keyword allows the control to hook up events, using the Handles syntax, with its owner. When adding components in the designer it automatically generates this for you but when creating them yourself you must include the WithEvents if you intend to use events with the component.

If you do not declare an object WithEvents then handlers must be assigned programmatically as they are in C# using AddHandler -- see : AddHandler

like image 186
J... Avatar answered May 18 '23 15:05

J...