Link to home
Start Free TrialLog in
Avatar of nigelr99
nigelr99Flag for United Kingdom of Great Britain and Northern Ireland

asked on

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

Hi,
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?
Thanks

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

Avatar of nigelr99
nigelr99
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

OK, not sure I asked the question very clearly so I'll try to highlight where I am with it.. this has my project on stop and I'm spending way too much time seemingly chasing my tail!

I have the 2 procedures shown on the same page code behind, the first gives no errors but the second gives "error BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types."

I'm simply trying to set field value(s) when a record is inserted, each new record has it's own id but is linked to the 'job' table by the job_id field.

I'd be most grateful for any leads.
Cheers.
'This one gives no errors:
'------------------------

Protected Sub FormView2_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles FormView2.ItemInserting
 'Insert new labour rate for current job. Enters selected labour rate and description into job_labour table as defaults

  Dim ctContent As Control
  Dim hourly_rate As Single, rate_description As String

  ctContent = Me.Controls(0).FindControl("Main")
  hourly_rate = CType(FindControlRecursive(ctContent, "ddl_customer_rates"), DropDownList).SelectedValue
  rate_description = CType(FindControlRecursive(ctContent, "ddl_customer_rates"), DropDownList).SelectedItem.ToString

  e.Values("hourly_rate") = hourly_rate
  e.Values("labour_rate_description") = rate_description
  e.Values("job_id") = Request.QueryString("job_id")

End Sub

'This one gives error
'----------------------
Protected Sub FormView3_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles FormView3.ItemInserting
  'Insert current job number into job_purchased table
   e.Values("job_id") = Request.QueryString("job_id")
End Sub

Open in new window

Avatar of Bob Learned
If the FormView is not a top-level control, you can't use the Handles, you would need to attach the event handler in code, or in the HTML designer (OnItemInserting).
Hi. I've only started learning asp.net 3 weeks ago so forgive me.. The formview is in a multiview within content on a masterpage so I guess it isn't top-layer. I'll look into how to add event handler. I still don't understand why I get this error for FormView3 when FormView2 is setup the same?
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks.. removed all the Handles and implemented as you suggested which fixed the error(s). Learning all the time - seems rather obvious now as these things tend to do.