Results 1 to 7 of 7

Thread: [RESOLVED] Handles clause requires a WithEvents variable - error

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    469

    Resolved [RESOLVED] Handles clause requires a WithEvents variable - error

    Hello

    I am getting a red underline in this line of code in my VS 2017 aspx.vb contact form:

    Name:  contact_submitted.jpg
Views: 4185
Size:  6.0 KB

    In my contact aspx form, I have

    Code:
    <button type="submit" class="contact_submitted">Send Now</button>
    The error I am getting is that 'a Handles clause requires a WithEvents variable' - I am not too sure what that means.

    Thanks for any help.

    Steve

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Handles clause requires a WithEvents variable - error

    The error means that either there is no object called contact_submitted, or (less likely) there an object called that but it isn't declared in a way that allows events.

    In this case it seems there is no object called contact_submitted... the code you showed has an object with no name, but has a class of contact_submitted. Try setting the name instead.

  3. #3
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Handles clause requires a WithEvents variable - error

    It's looking for a button that does not exist. Use server control and change the id to contact_submitted.
    Code:
    <asp:Button ID="contact_submitted" runat="server" Text="Button" />
    - kgc
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Handles clause requires a WithEvents variable - error

    Quote Originally Posted by KGComputers View Post
    Use server control
    Oops, how did I miss that!

  5. #5
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Handles clause requires a WithEvents variable - error

    Oops, how did I miss that!
    I guess there's a need to replace your reading glasses..Lol :-D
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    469

    Re: Handles clause requires a WithEvents variable - error

    Many thanks to you both for your kind replies.

    I was still getting a red underline under that final 'Click' (VS cannot find it), so I have replaced it with 'Load'. The error has now gone.

    Thanks again

  7. #7
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Handles clause requires a WithEvents variable - error

    cool! don't forget to mark this thread as resolved!
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width