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

nigelr99Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nigelr99Author Commented:
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

Bob LearnedCommented:
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).
nigelr99Author Commented:
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?
Bob LearnedCommented:
Here is how I would do it:

FormView.ItemInserted Event
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.formview.iteminserted.aspx

HTML:

<asp:FormView OnItemInserted="EmployeeFormView_ItemInserted" />

Open in new window


Code-behind:
Protected Sub EmployeeFormView_ItemInserted(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nigelr99Author Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.