Don’t Name User Controls and Web Pages the Same.

After spending some time developing an application using Visual Studio 2005 without the use of IIS I accumulated quite a few user controls and web pages that worked great in the dev environment.  However, after moving them to IIS I encountered a tricky little problem.  The error was:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0030: Cannot convert type ‘ASP.menu_aspx’ to ‘System.Web.UI.WebControls.Menu’

Source Error:

Line 118:        public menu_aspx() { 
Line 119:            string[] dependencies; 
Line 120: ((Menu)(this)).AppRelativeVirtualPath = "~/Menu.aspx"; 
Line 121: if ((global::ASP.menu_aspx.@__initialized == false)) { 
Line 122: dependencies = new string[6]; 

After playing around a bit I found that the user control worked fine if the page wasn’t the same name as the control.  Arg.  I don’t want to rename my aspx files because those are the names in the url.  I also didn’t want to rename the user controls either.

So what’s the fix.
Well as far as I can tell the quick fix is to rename the web page class name (i.e. not the aspx file name).

Menu.aspx.cs – (Appended ‘Page’ to the class name.)
publicpartialclassMenuPage : System.Web.UI.Page

Menu.aspx – (Also needed to update Inherits to match.)
<%@PageLanguage=”C#” CodeFile=”Menu.aspx.cs”Inherits=”MenuPage %>

If anyone finds a better way to solve, please post a comment.

Explore posts in the same categories: ASP.NET

2 Comments on “Don’t Name User Controls and Web Pages the Same.”

  1. Valentin Bornand Says:

    The SP1 of .NET Framewor 2 correct this problem.

    We can call our page with the name of a component…

  2. It worked for me. Very thanks

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: