Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
75 views
in Technique[技术] by (71.8m points)

c# - The name (of every control) does not exist in the current context

I'm trying to import a custom component into an existing web project to render multi-select drop down lists.

When I try to build the project, which built fine before I added these files, I'm getting "The name (of every control in the ASCX) does not exist" (in the code behind).

Except they do. So the error appears to be misleading and masking something else.

The ASCX file:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MultipleSelection.ascx.cs" Inherits="VallisLive2.Controls.MultipleSelection" %>
<%@ Register Assembly="CheckBoxListExCtrl" Namespace="CheckBoxListExCtrl" TagPrefix="cc1" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc2" %>

<div>
    <cc2:HoverMenuExtender ID="HoverMenuExtender1"
        runat="server"
        TargetControlID="MultiSelectDDL"
        PopupControlID="PanelPopUp"
        PopupPosition="bottom"
        OffsetX="6"
        PopDelay="25" HoverCssClass="popupHover">
    </cc2:HoverMenuExtender>

    <asp:DropDownList ID="MultiSelectDDL" CssClass="ddlMenu regularText" runat="server">
        <asp:ListItem Value="all">Select</asp:ListItem>
    </asp:DropDownList>

    <asp:Panel ID="PanelPopUp" CssClass="popupMenu" runat="server">
        <cc1:CheckBoxListExCtrl ID="CheckBoxListExCtrl1" CssClass="regularText" runat="server">
            <asp:ListItem Value="d1">Dummy 1</asp:ListItem>
            <asp:ListItem Value="d2">Dummy 2</asp:ListItem>
            <asp:ListItem Value="d3">Dummy 3</asp:ListItem>
            <asp:ListItem Value="d4">Dummy 4</asp:ListItem>
            <asp:ListItem Value="d5">Dummy 5</asp:ListItem>
            <asp:ListItem Value="d6">Dummy 6</asp:ListItem>
            <asp:ListItem Value="d7">Dummy 7</asp:ListItem>
            <asp:ListItem Value="d8">Dummy 8</asp:ListItem>
        </cc1:CheckBoxListExCtrl>
    </asp:Panel>
    <asp:HiddenField ID="hf_checkBoxValue" runat="server" />
    <asp:HiddenField ID="hf_checkBoxText" runat="server" />
    <asp:HiddenField ID="hf_checkBoxSelIndex" runat="server" />
</div>
<div id="ie6SelectTooltip" style="display: none; position: absolute; padding: 1px; border: 1px solid #333333; background-color: #fffedf; font-size: smaller; z-index: 99;"></div>

.. Nothing in this file is highlighted or underlined when viewing it in the editor. Next, the top part of the Code Behind file, "MultipleSelection.ascx.cs":


using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace VallisLive2.Controls
{
    public partial class MultipleSelection : System.Web.UI.UserControl
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            LoadJScript();
            LoadCss();

            //add attributes
            CheckBoxListExCtrl1.Attributes.Add("onclick", "readCheckBoxList('" +
                        CheckBoxListExCtrl1.ClientID + "','" + MultiSelectDDL.ClientID + "','" +
                        hf_checkBoxText.ClientID + "','" +
                        hf_checkBoxValue.ClientID + "','" + hf_checkBoxSelIndex.ClientID + "');");

            MultiSelectDDL.Attributes.Add("onmousemove", "showIE6Tooltip();");
            MultiSelectDDL.Attributes.Add("onmouseout", "hideIE6Tooltip();");

            if (!string.IsNullOrEmpty(hf_checkBoxValue.Value))
            {
                SetDropDownListText(hf_checkBoxValue.Value);
            }

            if (!string.IsNullOrEmpty(hf_checkBoxText.Value))
            {
                SetToolTip(hf_checkBoxText.Value);
            }
        }

Every reference to every control in the ASCX is underlined in red and throwing the error "The name .. does not exist in the current context".

The Build Action for the CodeBehind is "Compile".

The two DLLs referenced at the top of the ASCX file have been copied to the bin folder.

I've tried changing "CodeBehind=" to "CodeFile=" at the top of the ASCX file.

Can anyone suggest what the actual error is and how I go about getting VS2019 to build this? Thanks.

question from:https://stackoverflow.com/questions/65859263/the-name-of-every-control-does-not-exist-in-the-current-context

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...