Problem with the @Page directive in my Web form

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.

    Requires Free Membership to View

    When you register, you'll begin receiving targeted emails from my team of award-winning writers. Our goal is to provide a unique online resource for developers, architects and development managers tasked with building and maintaining enterprise applications using Visual Basic, C# and the Microsoft .NET platform.

    Hannah Smalltree, Editorial Director

    By submitting your registration information to SearchWinDevelopment.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchWinDevelopment.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

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