We help IT Professionals succeed at work.
Get Started

ASP.NET build error Handles clause requires a WithEvents variable BC30506

nigelr99 asked
Last Modified: 2012-05-11
I'm working on an aspx page with a couple of forms and gridviews and it works fine. I've added another small form to add some records, almost duplicating what I already have except it's for another table but I get the following build errors on 2 consecutive lines:

1. job.aspx.vb(77,0): error BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types
2. job.aspx.vb(78,0): error BC30451: 'sql_job_material' is not declared. It may be inaccessible due to its protection level.

The code causing this error is as shown, with line 77 being the declaration and the actual statement on line 78.
I have a duplicate procedure for FormView2 and a different table with no errors appearing for this. I've even tried declaring formview3 but of course it tells me this is already declared as  'protected withevents' so it seems it's just one big red herring?

I've looked at various solutions on the web, most of which suggesting a withevents declaration of some sort but why would I need it for this new sub when the others do not?

I've scanned for simple typos etc. but can find nothing. Anyone have any ideas where else I might look for a (hopefully very stupid) mistake please?

Protected Sub FormView3_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles FormView3.ItemInserting
            sql_job_material.UpdateParameters("job_id").DefaultValue = Request.QueryString("job_id")
End Sub

Open in new window

Watch Question
Most Valuable Expert 2012
Top Expert 2008
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE