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

I get the error

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

in the following code..

Public Sub selCurrentManuf_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles selCurrentManuf.SelectedIndexChanged

    End Sub

The drop list to go with it is the following...

<asp:DropDownList  
   OnSelectedIndexChanged="selCurrentManuf_SelectedIndexChanged" 
   selectedvalue='<%#Container.DataItem("c1_manufidcurrent")%>' 
    ID="selCurrentManuf" 
    Runat="Server" 
    DataTextField="c4_Desc" 
    DataValueField="c4_manufid"
    DataSource="<%# GetCurrentManuf() %>" 
    autopostback="true" 
 ></asp:DropDownList>
like image 432
Beginner Avatar asked Oct 06 '11 13:10

Beginner


2 Answers

I've gotten this error when for some I've renamed a field. For some reason sometimes the designer messes up and doesn't rename it in the form.aspx.designer.vb file, if you look in there and fix the name it can fix this issue if that has happened to you.

So double check that the field name is the same in your even handler, the aspx file and the designer.aspx files.

like image 160
Eric Hodges Avatar answered Sep 18 '22 16:09

Eric Hodges


I had encountered this issue when upgrading a legacy page. The problem is in the Inherits attribute @Page directive has the wrong namespace.

  1. Correct the namespace for Inherits attribute
  2. Remove the namespace in the designer file or match with it in the designer code
like image 44
Sridhar Nathani Avatar answered Sep 18 '22 16:09

Sridhar Nathani