Q

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.

This was first published in July 2003

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.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

SearchSOA

TheServerSide

SearchCloudApplications

Close