The type '_Default' already defines a member called 'Page_Load' with the same types of parameters

I renamed several classes and packages to my aspx project, and now I have this error:

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

I have two aspx pages. In the default.aspx codebehind file, 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 that I add to my project is automatically added to some namespace.

I tried to change attribute inheritance. But I could not find a way to fix this error and get rid of the namespace.

I am using Visual Studio 2010.

My project structure

+7
source share
5 answers

Each added page automatically adjusts to the namespace depending on the structure of your folder. I don’t see enough code and structure, but are you sure you don’t have the_Load page defined twice? At least this is an error message. Does it behave the same even if you use a different class name than _Default?

After editing:

Yes, there we go. You define the same class (_Default) in both Default.aspx and Search.aspx ... You must rename your classes according to conventions. i.e.: use the "Default" class in your Default.aspx and use the "Search" class in your Search.aspx

+6
source

Double-click on the error, temporarily rename Page_Load to another. Go down to the body of the function and enter Page_Load . Press F12. This will lead you to the place where the second Page_Load method already exists. You will probably see this in another partial _Default class in the same namespace.

+5
source

Just add a specific case.

You may encounter this situation when converting a website into a web application.

When your project is in the form of a website, when you add, for example, Default.aspx to two different folders, they are both created without a namespace with the same class name. Both are declared partial, and that's just fine. But when you convert to a web application and try to build, they start to contradict each other, because they are in the same namespace, partially declared and have their own Page_Load methods.

One solution can give different class names or encapsulate it in different namespaces according to the folder structure.

+3
source

Since your class is public partial class _Default , perhaps this causes some naming that causes the problem. Try to identify other _Default part (s). Since this is a partial class, you can have as many partial numbers as possible. The problem is probably that the load_page is defined in one of them.

+1
source

Listed below are the problems that I encountered when copying files to my solution, clicking on an error message or clicking on "Go to definition" mislead me to determine the cause. Hint - one line above .....!

I reveal the problem And how I finally solved it .

Errors while creating the application:

  • Error 1 Type "Solution1.Web.yourABC" already defines a member called "Page_Load" with the same parameters | C: \\ trunk \ Solution1.Web \ yourABC.aspx.cs 12 24
    Solution 1.Web

  • Error 2 Type "Solution1.Web.yourABC" already defines a member called "Page_Load" with the same parameters | C: \\ trunk \ Solution1.Web \ GuideABT.aspx.cs 12 24
    Solution1.Web

How the problem arose: I copy / paste the .aspx file in the same solution to create a new file. C #: There was an error like below; The worst other misleading errors started affecting the application at runtime:

* Keep in mind that error 1 is NOT an error, it is CORRECT, as this is the source code

 Error 1 Type 'Solution1.Web.yourABC' already defines a member called 'Page_Load' with the same parameter types C:\<folderpath>\trunk\Solution1.Web\yourABC.aspx.cs 12 24 Solution1.Web Error 2 Type 'Solution1.Web.yourABC' already defines a member called 'Page_Load' with the same parameter types C:\<folderpath>\trunk\Solution1.Web\GuideABT.aspx.cs 12 24 Solution1.Web 

Both "Page_Load" classes are empty, usually they are automatically generated by the Visual Studio Engine.

Solution : Modify the .cs file on the new aspx create / paste page to display the page name after the class name. In this case, "GuideABT.aspx" is the new attached and renamed aspx file:

Correction for error 1: NO CORRECTION NECESSARY, since it is copied from a file. MAKE SURE the file name and the name of the reference to the ARE class are the same in the .cs files:

File name yourABC.aspx, check the .cs extension files:

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

Bug Fix 2: EDIT file attachment. Correct the CLASS NAME to display the .aspx file name.

File name GuideABT.aspx, check the .cs extension files: ORIGINAL code in .cs

 namespace Solution1.Web { public partial class *yourABC* : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } } } 

FIXED this code in .cs TO

 namespace Solution1.Web { public partial class **GuideABT** : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } } } 

Problem RESOLVED.

Greetings.

0
source

All Articles