The name 'xxx' does not exist in current c

2020-07-27 03:54发布

I have this statemen at the beginning:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ucCreditCard.ascx.cs"
    Inherits="UserControls_Common_ucCreditCard" %>

in ucCreditCard.ascx.cs I have this:

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class UserControls_User_ucCreditCard : System.Web.UI.UserControl
{
//
}

When I try to reference any of the simple control like Textbox etc, I always get control 'xxx' does not exist in current content. What can be the problem?

Thanks in advance :)

标签: c# asp.net
10条回答
Root(大扎)
2楼-- · 2020-07-27 04:19

Hope You are missing the designer file, as these errors mostly occur only in such cases, Right click and convert to web application. should do the trick.

Also do check that its the same as the partial class defined in your .cs file

查看更多
倾城 Initia
3楼-- · 2020-07-27 04:20

Here the solution. You missing to declare the project.

using System.Xml.Linq;
namespace YouProjectName
{
public partial class UserControls_Common_ucCreditCard : System.Web.UI.UserControl
{
//
}
} // end of namespace.
查看更多
smile是对你的礼貌
4楼-- · 2020-07-27 04:21
  • This issue for me was caused by another error in the application
  • I tried rebuilding the solution and was getting only this error and no others
  • So I rebuilt just the project with the problem
  • Another error appeared
  • I fixed this - turns out it was blocking correct compilation of the user control
  • Now works fine!
查看更多
女痞
5楼-- · 2020-07-27 04:23

select "Convert to web application" it will create new .aspx.designer.cs file. Then Build would resolve the problem

查看更多
太酷不给撩
6楼-- · 2020-07-27 04:26

To illustrate what V4Vendetta sayed ther is an exemple inyour case with a dropDownList.

UserControls_Common_ucCreditCard.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ucCreditCard.ascx.cs"
    Inherits="UserControls_Common_ucCreditCard" %>

//Exemple with a Drop down list
<asp:DropDownList ID="drpMain" runat="server" Width="200px" Visible="true">

ucCreditCard.ascx.designer.cs

    //Namespace must be the same in ucCreditCard.ascx.designer.cs and in ucCreditCard.ascx.cs
namespace NameOfYourProject {
                        public partial class UserControls_User_ucCreditCard {

                            protected global::System.Web.UI.WebControls.DropDownList drpMain;
                    }
}

ucCreditCard.ascx.cs

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


namespace NameOfYourProject
{
public partial class UserControls_User_ucCreditCard : System.Web.UI.UserControl
{
// You can refer drpMain
}
查看更多
爱情/是我丢掉的垃圾
7楼-- · 2020-07-27 04:28

You must have changed the name of your file but did not update the name of your class:

You have:

public partial class UserControls_User_ucCreditCard : System.Web.UI.UserControl
{
//
}

should be

public partial class UserControls_Common_ucCreditCard : System.Web.UI.UserControl
{
//
}

as indicated in the .aspx portion of your code.

查看更多
登录 后发表回答