16

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>
Beginner
  • 28,539
  • 63
  • 155
  • 235

10 Answers10

8

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.

Eric Hodges
  • 361
  • 2
  • 5
  • 1
    Instead of opening designer files in text editor, it is possible to simply rename a control and its event handler and then rename them back to fix this corruption issue. – ajeh Jul 03 '14 at 21:19
  • Close and reopen the solution worked for me (renaming, or rebuilding did not) – Pierre Apr 05 '18 at 19:54
5

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
Sridhar Nathani
  • 101
  • 1
  • 1
1

I had this happen on the OnClick event for a button. I originally the button inside a panel inside of an ItemTemplate for a gridview column. I only needed the panel to popup on some other buttons OnClick event so I didn't really need it repeated through out the grid. It was hidden anyhow. I moved the panel outside the gridview all together and the error went away.

glitzsfa
  • 353
  • 1
  • 2
  • 14
1

When converting a legacy Web Sites Project to a Web Application Project type, when following these directions, after converting the application, it created a bunch of .aspx.designer.vb files for me but didn't include them in the project. So I clicked on the project root in solution explorer, pressed the * key to expand everything, then multiselected all of the designer.vb files and right-clicked then said 'include in project'. Then it was able to see the types and the compiler lived happily ever after.

THE END

Dan Csharpster
  • 2,662
  • 1
  • 26
  • 50
1

Actually there is some fault in the designer. Closing and Re-Opening the solution fixes it

0

I had this happen when I created a command button. When I let VB.net create the event I was immediately greeted with that error. What I did to fix it was deleted the object in the designer (a command button in my case), the code tied to it, saving my .sln & recreating the object. Problem solved.

John Waclawski
  • 936
  • 1
  • 11
  • 20
0

I had this error on a handler function for an ASP button on vb.net. Solved by adding

runat="server"

to the enclosing form tag

<form name="formUpdate" method="post" id="frmUpdate" runat="server">
     <asp:Button ID="btnUpdate" runat="server" Text="Update" />
 </form>
Lumnut
  • 1
  • 3
0

I got this error randomly 268 times in a solution that I hadn't changed. I closed and reopened the file and it seemed to fix it...

Frez
  • 33
  • 1
  • 2
    Hi there. This is not the answer. Please edit your post or delete it regarding the community policy. – Gen Wan Apr 26 '19 at 20:27
0

I encountered this error in a solution while testing something. It is related to Designer.vb related to the form. Make sure that it was updated.

0

Error may like this in winform vb.net enter image description here

solution: enter image description here

Change this :

  Public button3 As Button

TO:

  Public WithEvents button3 As Button
lava
  • 6,020
  • 2
  • 31
  • 28