设计时错误 - 具有相同Id的多个控件

时间:2021-02-17 12:47:27

I'm using VS 2008, I have a very simple page that has a bunch of uniquely named controls. When I try to view it in design mode I get the following error:

我正在使用VS 2008,我有一个非常简单的页面,它有一堆独特的命名控件。当我尝试在设计模式下查看它时,我收到以下错误:

Error Rendering Control - Label12
An unhanded exception has occurred.
Multiple controls with the same ID 'Label1' were found. FindControl requires that controls have unique IDs

I've checked the HTML and the designer file and I can only see one control called Label1. What might be causing this?

我检查了HTML和设计器文件,我只能看到一个名为Label1的控件。可能是什么导致了这个?

Also, here is the aspx markup I'm having trouble with?

另外,这是我遇到麻烦的aspx标记?

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="CoachingAppearanceReport.aspx.vb"
    Inherits="AcademyPro.CoachingAppearanceReport" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <div id="appearanceDetail" class="Left CriteriaContainer">
                <asp:Label ID="Label1" runat="server" Text="Appearance Type" AssociatedControlID="ddlAppearanceType" />
                <asp:DropDownList ID="ddlAppearanceType" runat="server" CssClass="AppType" OnDataBound="ddlAppearanceType_DataBound"
                    DataSourceID="odsAppearanceType" DataTextField="AppearanceType" DataValueField="AppearanceTypeCode">
                </asp:DropDownList>
                <asp:RequiredFieldValidator ID="rfvAppearanceType" runat="server" 
                    ControlToValidate="ddlAppearanceType" InitialValue="" Text="*"
                    ErrorMessage="The appearance type must be selected" />
                <asp:Label ID="lblAppearanceType" runat="server" />
                <br />

                <div class="SubSettings">
                    <asp:Label ID="Label12" runat="server" Text="Subbed for" AssociatedControlID="ddlSubbedFor" />
                    <asp:DropDownList ID="ddlSubbedFor" runat="server" OnDataBound="ddlSubbedFor_DataBound"
                        DataSourceID="odsPlayersInAgeGroup" DataTextField="PlayerName" DataValueField="PlayerID">
                    </asp:DropDownList>
                    <asp:Label ID="lblSubbedFor" runat="server" />
                    <br />
                    <asp:Label ID="Label13" runat="server" Text="Mins" AssociatedControlID="txtSubMins" />                    
                    <asp:TextBox ID="txtSubMins" runat="server" MaxLength="3" CssClass="TinyWidth" />
                    <asp:Label ID="lblSubMins" runat="server" />
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
</html>

2 个解决方案

#1


Is this a 'web application project'?

这是一个“网络应用程序项目”吗?

It's possible that your '.designer.cs' file is corrupted/out of date and has two copies of "Label1" within it, which could be causing your problem.

您的'.designer.cs'文件可能已损坏/过期,并且其中包含两个“Label1”副本,这可能会导致您的问题。

If this is the case, delete the contents of the '.designer.cs' file and the go back into your markup. Add a newline after the header line on the file, save the page, and then remove the line and save the page. This will force a re-generation of the designer, which may fix the problem.

如果是这种情况,请删除'.designer.cs'文件的内容并返回标记。在文件标题行后添加换行符,保存页面,然后删除该行并保存页面。这将迫使设计师重新生成,这可能会解决问题。

#2


I just discovered the same thing - its the AssociatedControlID on an asp:label. When I remove that the designer error goes away. WTH?

我刚刚发现了同样的东西 - 它是asp:标签上的AssociatedControlID。当我删除时,设计师错误就消失了。 WTH?

#1


Is this a 'web application project'?

这是一个“网络应用程序项目”吗?

It's possible that your '.designer.cs' file is corrupted/out of date and has two copies of "Label1" within it, which could be causing your problem.

您的'.designer.cs'文件可能已损坏/过期,并且其中包含两个“Label1”副本,这可能会导致您的问题。

If this is the case, delete the contents of the '.designer.cs' file and the go back into your markup. Add a newline after the header line on the file, save the page, and then remove the line and save the page. This will force a re-generation of the designer, which may fix the problem.

如果是这种情况,请删除'.designer.cs'文件的内容并返回标记。在文件标题行后添加换行符,保存页面,然后删除该行并保存页面。这将迫使设计师重新生成,这可能会解决问题。

#2


I just discovered the same thing - its the AssociatedControlID on an asp:label. When I remove that the designer error goes away. WTH?

我刚刚发现了同样的东西 - 它是asp:标签上的AssociatedControlID。当我删除时,设计师错误就消失了。 WTH?