Solved

VB Code is giving error Handles clause requires a WithEvents variable.

Posted on 2009-07-15
4
607 Views
Last Modified: 2012-05-07
I have a form that is giving me the following error "Handles clause requires a WithEvents variable" how do I fix my problem?
Button on *.aspx form

<asp:Button ID="InsertButton" runat="server" CausesValidation="True"

                         CommandName="Insert" Text="Submit"/>   
 

Code in *.aspx.vb

Protected Sub InsertButton_Command(ByVal sender As Object, _

    ByVal e As System.Web.UI.WebControls.CommandEventArgs) Handles InsertButton.Command

        Server.Transfer("~/ContentPages/Testimonials.aspx", False)

    End Sub

Open in new window

0
Comment
Question by:Robert Treadwell
  • 2
4 Comments
 
LVL 15

Expert Comment

by:mohan_sekar
Comment Utility
Protected WithEvents InsertButton As Button is missing in the designer file. Did you delete and recreate the control?
0
 

Author Comment

by:Robert Treadwell
Comment Utility
I added the withEvents sub, now I not getting the error but my page is not being transfered to the next page.  See the code below to see if that may help you help me.


Partial Class ContentPages_Testimonial

    Inherits System.Web.UI.Page
 

    Protected Sub InsertButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) _

    Handles InsertButton.Click

        Server.Transfer("~/ContentPages/Testimonials.aspx", False)

    End Sub
 

    Protected WithEvents InsertButton As Button
 

End Class

Open in new window

0
 
LVL 15

Accepted Solution

by:
mohan_sekar earned 250 total points
Comment Utility
Did you set a breakpoint and see whether the the Sub is getting called?
0
 
LVL 9

Expert Comment

by:sevensnake77
Comment Utility
what was the with events variable
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now