Re: Control does not exist in the current context error in VS 2008

  •  05-05-2009, 8:38 PM

    Re: Control does not exist in the current context error in VS 2008

    ASPX PAGE
    -----------------------------------------
     
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestEditor.aspx.cs" Inherits="CMS.TestEditor" %>
    <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
    <!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>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <CE:Editor ID="cuteEditor" runat="server" Autoconfigure="Simple" />  
        
            <br />
            <asp:Button ID="submitButton" runat="server" Text="Save" OnClick="submitButton_Click" />
            
            <hr />
            
            <asp:Literal ID="htmlText" runat="server" />
        </div>
        </form>
    </body>
    </html>
     
    -------------------------------
    CODE BEHIND
    -------------------------------
    using System;
    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 CMS
    {
        public partial class TestEditor : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {

            }

            protected void submitButton_Click(object sender, EventArgs e)
            {
                htmlText.Text = cuteEditor.Text;
            }
        }
    }
     
     -----------------------
     DESIGNER FILE
    --------------------------
    namespace CMS {
       
        public partial class TestEditor {
            
            /// <summary>
            /// form1 control.
            /// </summary>
            /// <remarks>
            /// Auto-generated field.
            /// To modify move field declaration from designer file to code-behind file.
            /// </remarks>
            protected global::System.Web.UI.HtmlControls.HtmlForm form1;
        }
    }
     
    ----------------------------
     
    So as you can see the controls aren't getting added to the designer file so it doesn't know about the controls in the code behind file.
     
    This is the error that I am getting when I try to run the page.
     
    Error    4    The name 'htmlText' does not exist in the current context    C:\Projects\CMS\CMS\TestEditor.aspx.cs    25    13    CMS
    Error    5    The name 'cuteEditor' does not exist in the current context    C:\Projects\CMS\CMS\TestEditor.aspx.cs    25    29    CMS
     
    If I get rid of the Editor control then it runs and the designer file has the appropriate controls in it.
     
     
    Thanks,
     
    Jeff
View Complete Thread