Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 748
ThdK Avatar asked Apr 01 '11 08:04

ThdK


3 Answers

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

like image 50
Damb Avatar answered Nov 18 '22 07:11

Damb


Double click the error, temporarily rename the Page_Load to something else. Go down into the body of the function and type Page_Load. Press F12. That will get you to the place where you have second Page_Load method already defined. You'll probably see that it's in another partial _Default class in the same namespace.

like image 6
František Žiačik Avatar answered Nov 18 '22 08:11

František Žiačik


Just to add up a specific case.

You can come across to this situation when you convert Web Site into Web Application.

When your project in form of Web Site, when you add for example Default.aspx into two different folders they both created without namespace with the same class name. Both declared partial and it is just fine. But when you convert into Web Application and try to build they start conflicting as they are in the same namespace, declared partial and have their own Page_Load methods.

One of the solutions can be giving distinct class names or encapsulating into different namespaces in accordance with the folder structure.

like image 4
Oybek Avatar answered Nov 18 '22 07:11

Oybek