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.
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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With