422,734 Members | 1,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,734 IT Pros & Developers. It's quick & easy.

'Handles clause requires a WithEvents variable - error

P: 44
Hello Frinavale

I have removed the Focus() for the time being.

You may remember suggesting the following:

Expand|Select|Wrap|Line Numbers
  1. Private Sub SendEmail_Click(sender As Object, e As System.EventArgs) Handles SendEmail.Click
I get a red underline: 'Handles clause requires a WithEvents variable defined in the containing type or one of its base types'. That is the only error I get in that aspx.vb file.

In the corresponding aspx file, I have:

Expand|Select|Wrap|Line Numbers
  1. <asp:Button ID="SendEmail" runat="server" Cssclass="astext" Text="[Send]" />
Is there anything obvious to you that I am doing wrong?

Thanks again for your patience.
Dec 5 '17 #1
Share this Question
Share on Google+
13 Replies


Frinavale
Expert Mod 5K+
P: 9,731
Huh...

Ok, show me the code at the top of your ASP.NET markup along with the top class definition for the VB.NET code.

I think you may have changed a class name or something and these files are no longer linked together.
Dec 6 '17 #2

P: 44
Thanks again.

In the aspx file, I have:

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Title="Contact" Language="VB" AutoEventWireup="false" CodeBehind="Contact.aspx.vb" %>
and in the aspx.vb file, I have:

Expand|Select|Wrap|Line Numbers
  1. Public Class Contact
  2.     Inherits System.Web.UI.Page
Dec 6 '17 #3

Frinavale
Expert Mod 5K+
P: 9,731
Your ASP.NET code is missing the Inherits attribute.

It should look something like this:

<%@ Page Title="Contact" Language="VB" AutoEventWireup="false" CodeBehind="Contact.aspx.vb" Inherits="MyNamespace.Contact" %>

Where MyNamespace is the namespace that your Contact class belongs to (by default, your namespace has the same name as your project).
Dec 6 '17 #4

P: 44
I can't see that that has changed anything - please see screenshots:







That red underline, under SendMail (Frina3.jpg), still persists.
Dec 6 '17 #5

Frinavale
Expert Mod 5K+
P: 9,731
You need to replace MyNamespace with your actual namespace...

What is the name of your project?
By default it is the name of your project.
Dec 6 '17 #6

P: 44
The name of the project is BayingWolf:



So I now have this along the top of Contact.aspx:

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Title="Contact" Language="VB" AutoEventWireup="false" CodeBehind="Contact.aspx.vb" Inherits="BayingWolf.Contact" %>
That stubborn red underline is still there under SendMail
Dec 6 '17 #7

Frinavale
Expert Mod 5K+
P: 9,731
Try closing and reopening visual studio and then rebuilding the project. (Rebuild clears out stuff that regular build doesn't)
Dec 6 '17 #8

P: 44
I have restarted it. When I compile it, I get this from Command Prompt:

Contact.aspx(1): error ASPPARSE: Could not load type 'BayingWolf.Contact'.


I will try it without BayingWolf and just Contact.
Dec 6 '17 #9

P: 44
Without BayingWolf and only Contact, I get a similar error:

error ASPPARSE: Could not load type 'Contact'.
Dec 6 '17 #10

Frinavale
Expert Mod 5K+
P: 9,731
Add a new form.
Exclude this one from the project.
Add a button to the form and handle it's click event..
Can you compile?
Dec 6 '17 #11

P: 44
This is the state of play:

With this:

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Title="Contact" Language="VB" AutoEventWireup="false" CodeBehind="Contact.aspx.vb" Inherits="Contact" %>
In other words, without the project name, the error under 'SendMail' has disappeared. The problem is that I get the Cmd error:

error ASPPARSE: Could not load type 'Contact'.

I have just tried it again. I am sure this is close to being resolved.
Dec 6 '17 #12

P: 44
Do you mean add a new web form to BayingWolf?
Dec 6 '17 #13

P: 44
I compile aspx projects through PowerShell or Cmd Prompt - I don't know how to do it from within VS.

Almost there. I have created a test project called Frina. No errors. Top line looks like this:

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Title="Contact" Language="VB" AutoEventWireup="false" CodeFile="Contact.aspx.vb" Inherits="Contact" %>
No error under SendMail and it compiles, but on the server (external Web hosting service), I get this:

An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

It points to this:

Source File: E:\HostingSpaces\dimadayo\dimadayoub.net\wwwroot\f rina\web.config Line: 19

On Notepad++ (with its line numbering), line 19 is this authentication mode:

Expand|Select|Wrap|Line Numbers
  1. <system.web>
  2.     <authentication mode="None"/>
  3.     <compilation debug="false" targetFramework="4.5.2"/>
  4.     <httpRuntime targetFramework="4.5.2"/>
Dec 6 '17 #14

Post your reply

Sign in to post your reply or Sign up for a free account.