Error BC30506 trying to add even for a button

  • Thread starter Thread starter Dennis
  • Start date Start date
D

Dennis

I have a page in ASP.NET 2.0. I add a button in design view and the
page runs fine. I then double-click the button to create the click
method in the code. Then when I run the page I get the error "error
BC30506: Handles clause requires a WithEvents variable defined in the
containing type or one of its base types."

I have tried deleting the button and re-adding it numerous times with
different names and every time I get the same error. I have another
button on the page that works fine. All the info on this error talks
about if the control is dynamically created, there is nothing that
talks about if it is created as part of the page design. Does anyone
know how to fix it?

Thanks.
 
I have a page in ASP.NET 2.0. I add a button in design view and the
page runs fine. I then double-click the button to create the click
method in the code. Then when I run the page I get the error "error
BC30506: Handles clause requires a WithEvents variable defined in the
containing type or one of its base types."

I have tried deleting the button and re-adding it numerous times with
different names and every time I get the same error. I have another
button on the page that works fine. All the info on this error talks
about if the control is dynamically created, there is nothing that
talks about if it is created as part of the page design. Does anyone
know how to fix it?

Thanks.

http://msdn2.microsoft.com/en-us/library/32787dt6(vs.80).aspx
 
So where do I add the withevents variable? Here is my handles clause:

Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSave.Click

And why do I have to do this now? I've never had to do it in any other
page I've created and I didn't have to do it with the other button on
the page, that one works just fine.
 
So where do I add the withevents variable? Here is my handles clause:

Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSave.Click

And why do I have to do this now? I've never had to do it in any other
page I've created and I didn't have to do it with the other button on
the page, that one works just fine.




- Show quoted text -

The WithEvents statement and the Handles clause provide a declarative
way of specifying event handlers. An event raised by an object
declared with the WithEvents keyword can be handled by any procedure
with a Handles statement for that event

Protected WithEvents btnSave As System.Web.UI.WebControls.Button

.....

Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSave.Click
 
But I'm not dynamically creating the button. I'm just dropping it
onto the page in design view - it has an asp:Button tag in source
view. There is no declaration statement.
 
I had exactly this problem too. I solved it by creating a new aspx and
code-behind file then copying and pasting the content from the problem page
to the new one. The new page worked just fine. Seems it was the IDE, not me,
getting things wrong.
 
Back
Top