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条回答
SAY GOODBYE
2楼-- · 2020-07-27 04:32

Same problem here, but with a User Control. Now solved.

In my case, the issue was the designer file being generated in a different namespace than the main one rather than just a missing file. Don't ask me how it happened.

查看更多
叛逆
3楼-- · 2020-07-27 04:33

Using different form and user control name will solve your problem.

查看更多
该账号已被封号
4楼-- · 2020-07-27 04:34

I just ran into this after I copied/pasted an ascx user control for which I'm going to make a breaking change and it needed to be "versioned". I had adjusted the class names but the references to page controls on the original ascx code behind still barfed until I made sure the full namespace.classname was being used in the ascx page "Inherits" property.

查看更多
够拽才男人
5楼-- · 2020-07-27 04:35

There is another situation when you get this error. It is when multiple aspx pages refers to the same code page. This generally happens when you have made a copy of the page and then changed the page name but forgot to change the inherits tag.

To find out this just search the text inside the inherits tag, in the whole project and if there is more than one occurrence of the text in aspx pages then just do the modification accordingly.

查看更多
登录 后发表回答