Type '_Default' already defines a member called 'Page_Load' with the same parameter types

ThdK picture ThdK · Apr 1, 2011 · Viewed 38.6k times · Source

I've been renaming some classes and packages in my aspx project and now i have this error:

"Type '_Default' already defines a member called 'Page_Load' with the same parameter types"

I have two aspx pages. In the default.aspx codebehind i see:

Default.aspx:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="_Default" %>

Default.aspx.cs:

public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        //error line under 'Page_Load'
    }

search.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="search.aspx.cs" Inherits="_Default" %>

search.aspx.cs:

public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)

    }

Every new ASPX page I add to my project is automaticly added to some namespace.

I've tried changing the inherits attribuut. But i couldn't find a way to fix this error and to get rid of the namespace.

I'm using Visual Studio 2010.

My project structure

Answer

Damb picture Damb · Apr 1, 2011

Every page you add is automatically configured to namespace depending on your folder structure. I don't see enough code and structure, but are you sure, that you don't have the Page_Load defined twice? At least the error message says so. Does it behave same even when you use different class name than _Default ?

After edits:

Yea, there we go. You define same class (_Default) in both Default.aspx and Search.aspx ... You should rename your classes according to conventions. ie: use class "Default" in your Default.aspx and use class "Search" in your Search.aspx