Problem solve Get help with specific problems with your technologies, process and projects.

Problem with the @Page directive in my Web form

Thank you for any attempt to help me. My problem: After creating a Web form page that works with no errors, I try to reopen it later and get this error message:

"The file failed to load in the Web Form designer. Please correct the following error, then load it again: Visual Studio cannot open a designer for that file because the class within it does not inherit from a class that can be visually designed."

My main page has this at the top:

<%@ Page Language="vb" src="WebForm2.aspx.vb" Inherits="WebForm2"%>

And my code behind page has:

Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls.DropDownList
Imports System.Web.UI.WebControls.Button
Imports System.Data

Public Class WebForm2

Inherits Page    ( also tried   Inherits System.Web.UI.Page )

Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents Button1 As System.Web.UI.WebControls.Button

I believe the problem is in the code behind page, because if I change <%@ Page Language="vb" src="WebForm2.aspx.vb" Inherits="WebForm2"%> to <%@ Page Language="vb" %>, there is no problem.

Again any help you can offer would be greatly appreciated. Thank you.
The problem definitely is the @Page directive. VB.NET adds all classes to the default namespace specified for the project properties, like MyWebApp, which usually is both the application name and the compiled assembly name. This namespace must be added to the Inherits attribute, such as: Inherits="MyWebApp.WebForm2." That may do the trick.

Dig Deeper on .NET tutorials, guides and quizzes

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.