Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Add a new WebForm(with master page) and drag the user control on it.When I build the solution it shows this error-"member names cannot be the same as their enclosing type"

What I have tried:

HTML
<%@ Page Title="" Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true" CodeBehind="BuyerInspection.aspx.cs" Inherits="WebApp.Pages.BuyerInspection" %>
<%@ Register Src="~/Controls/BuyerInspection.ascx" TagPrefix="uc" TagName="BuyerInspection" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PageTitleContentPlaceHolder" runat="Server">Bank Payment
<asp:Content ID="Content2" ContentPlaceHolderID="PageContentPlaceHolder" runat="Server">
    <div data-flow="row">
        <uc:BuyerInspection ID="BuyerInspection"  runat="server"></div>
Posted
v2
Comments
Satish Padnani 29-Jun-16 3:05am    
I had same problem ! right now will upload a solution soon
Sergey Alexandrovich Kryukov 29-Jun-16 3:12am    
You did not show the definition of the type with your bug. But what's unclear in this error message? Visual Studio should show you then problematic code. Find out the members with the same name as the type...
—SA
I think "BuyerInspection" is conflicting. Try different name for the user control.

1 solution

The ID of your control is BuyerInspection and the type of the control is also BuyerInspection, as is the class of your page, so behind the scenes (in your designer file) you have something like this;

C#
public partial class BuyerInspection
{
    protected BuyerInspection BuyerInspection;
}


In .net you can't have a property name that is the same as the class name, so you can fix this by calling your control something else

<uc:BuyerInspection ID="ucBuyerInspection"  runat="server">


which will change the code to

C#
public partial class BuyerInspection
{
    protected BuyerInspection ucBuyerInspection;
}


In general you need to employ better naming conventions anyway, I would give the control's type a name that reflects it is a control to distinguish it from the page of the same name.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900