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.)
public partial class MenuPage : System.Web.UI.Page
Menu.aspx – (Also needed to update Inherits to match.)
<%@ Page Language=”C#” CodeFile=”Menu.aspx.cs” Inherits=”MenuPage“ %>
If anyone finds a better way to solve, please post a comment.
December 8, 2008 at 6:59 am
The SP1 of .NET Framewor 2 correct this problem.
We can call our page with the name of a component…
April 7, 2009 at 3:56 pm
It worked for me. Very thanks