How to solve error: The name 'xxxxxx' does not exist in the current context
Home » C# ASP.Net Tips » How to solve error: The name 'xxxxx' does not exist in the current context
Visits:
18163
OnLine:
69
Last Updated:
Wed, Jul 31, 2013
Problem
You've written an ASP.Net Web page with some ASP.Net or DevExpress controls, say with a Literal control named Literal1:
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
and when you try to access this control using its name in the Code Behind file you get the following error:
The name 'Literal1' does not exist in the current context
Solution
Right click the page in Solution Explorer or right click the folder containing this page and select:
Convert to Web Application
This creates a WebPageName.aspx.designer.cs file containing declarations of your controls like this:
/// <summary>
/// Literal1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Literal Literal1;
and from there on you'll be able to use them by their name in your Web Application Code Behind files.