Can't create an event handler on Web Form in Visual Studio 2017 (VB)

  • Thread starter Thread starter SRC18
  • Start date Start date
S

SRC18

Guest
These are the steps I followed:

File --> New Project
Selected ASP.NET Web Application (.NET Framework 4.6.1)
Selected Empty Web Site
Then, Add New Web Form and named it Default.aspx

I can now add controls to the form and double click the button to create the event handler. All works fine. But, after I close it and re-open it (either as Open Project or as Open Website) I can no longer double click on a control to create the event handler. I get the message: Could not complete the action.

In addition, all the control-names are underlined in red in the VB code and I get the following the error messages:

Severity Code Description Project File Line Suppression State
Error BC30451 'Label1' is not declared. It may be inaccessible due to its protection level.

Severity Code Description Project File Line Suppression State
Error BC30506 Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

It will run but I cannot create event handlers by double clicking on the control and the controls are not listed in the drop down box on the code behind screen.

Here is a sample of a simple web page I created to show you the errors. I have noticed that the Inherits name in the page directive is different from the class-name in the VB. Am I doing something wrong during the creation of my web pages? I reinstalled Visual Studio 2017 and still have the same problem.

Public Class _Default
Inherits System.Web.UI.Page

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label1.Text = "Help!"
End Sub

End Class

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebTest2._Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br /> <br />
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>

Continue reading...
 
Back
Top