C# <;HtmlContent>;在当前上下文中不存在

C# <;HtmlContent>;在当前上下文中不存在,c#,asp.net,class,stored-procedures,C#,Asp.net,Class,Stored Procedures,出现一个错误,当前上下文中不存在HtmlContent。有人能帮我理解为什么VisualStudio会给出这个错误吗 private void WriteEmployeesList() { StringBuilder htmlStr = new StringBuilder(""); int numEmployees = db.CountEmployees(); htmlStr.Append("<br />Total empl

出现一个错误,当前上下文中不存在HtmlContent。有人能帮我理解为什么VisualStudio会给出这个错误吗

  private void WriteEmployeesList()
    {
        StringBuilder htmlStr = new StringBuilder("");
        int numEmployees = db.CountEmployees();
        htmlStr.Append("<br />Total employees: <b>");
        htmlStr.Append(numEmployees.ToString());
        htmlStr.Append("</b><br /><br />");
        List<EmployeeDetails> employees = db.GetEmployees();
        foreach (EmployeeDetails emp in employees)
        {
            htmlStr.Append("<li>");
            htmlStr.Append(emp.EmployeeID);
            htmlStr.Append(" ");
            htmlStr.Append(emp.TitleOfCourtesy);
            htmlStr.Append(" <b>");
            htmlStr.Append(emp.FirstName);
            htmlStr.Append("</b>, ");
            htmlStr.Append(emp.LastName);
            htmlStr.Append("</li>");
        }
        htmlStr.Append("<br />");
        HtmlContext.Text += htmlStr.ToString();
    }

protected void Page_Load(object sender, EventArgs e)
        {

            WriteEmployeesList();
            // The ID value is simply set to 0, because it's generated by the
            // database server and filled in automatically when you call
            // InsertEmployee().
            int empID = db.InsertEmployee(new EmployeeDetails(0, "Mr.", "Bellinaso", "Marco"));

            HtmlContent.Text += "<br />Inserted 1 employee.<br />";
            WriteEmployeesList();
            db.DeleteEmployee(empID);
            HtmlContent.Text += "<br />Deleted 1 employee.<br />";
            WriteEmployeesList();
        }


<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <asp:Literal ID="Literal1" runat="server" Text="HtmlContent"></asp:Literal>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Welcome to ASP.NET!
    </h2>
    <p>
        To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">
            www.asp.net</a>.
    </p>
    <p>
        You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409"
            title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
    </p>
</asp:Content>   
private void WriteEmployeesList()
{
StringBuilder htmlStr=新的StringBuilder(“”);
int numEmployees=db.CountEmployees();
htmlStr.Append(“
员工总数:”); Append(numEmployees.ToString()); htmlStr.Append(“

”); List employees=db.GetEmployees(); foreach(员工详细emp员工) { htmlStr.Append(“
  • ”); htmlStr.Append(emp.EmployeeID); htmlStr.追加(“”); htmlStr.Append(帝国标题); htmlStr.追加(“”); htmlStr.Append(emp.FirstName); htmlStr.追加(“,”); htmlStr.Append(emp.LastName); htmlStr.Append(“
  • ”); } htmlStr.Append(“
    ”); HtmlContext.Text+=htmlStr.ToString(); } 受保护的无效页面加载(对象发送方、事件参数e) { WriteEmployeesList(); //ID值只是设置为0,因为它是由 //数据库服务器,并在调用时自动填写 //InsertEmployee()。 int empID=db.InsertEmployee(新员工详细信息(0,“先生”,“贝利纳索”,“马可”); HtmlContent.Text+=“
    插入1名员工。
    ”; WriteEmployeesList(); db.DeleteEmployee(empID); HtmlContent.Text+=“
    删除了1名员工。
    ”; WriteEmployeesList(); } .

    你也可以找到。


    只是猜测,但尝试包括
    初始化组件()在页面加载函数中。它需要出现在其他任何东西之前,所以把它放在第一行


    或者,检查@Page指令上的代码隐藏文件名和继承属性,确保两者匹配。

    htmlContent必须在.aspx页面中将此名称声明为标签或div或其他容器。然后,您将能够填充,代码将尽我所能工作。 htmlContent不是关键字、方法或对象。它只是.aspx端的一个html元素的名称。 亲切问候,,
    Ola Balstad

    如果您发布了实际导致错误的代码部分,不是更好吗?请发布完整的异常详细信息,包括堆栈跟踪。我已经编辑了代码。请显示创建控件的ASPX或C代码,以及错误发生在哪一行?请告诉显示错误的行号,