Reputation: 13853
I created a branch new web project: File -> New -> Project -> ASP.NET Web Application
Then I tried to add a simple control asp:Label but the aspx.cs doesn't recognize this declaration for some reasons. I didn't make any changes to the default project. It contains 6 pages:
Does anyone know what could cause this issue? Thanks.
EDIT
Here what I added to the file About.aspx
is a label with id = id1
<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="About.aspx.cs" Inherits="WebApplication2.About" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:label ID="id1" runat="server" >A Label</asp:label>
<h2>
About
</h2>
<p>
Put content here.
</p>
</asp:Content>
I ran the project without calling that variable id1
, everything works fine.
But if I called id1
within About.aspx.cs
, it gave me error said the variable was not found.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2 {
public partial class About : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
id1.Text = "What the heck?";
}
}
}
Upvotes: 1
Views: 12269
Reputation: 4361
Based on you comment it seems your your About.aspx.designer.cs
file is missing the Label definition. Delete your About.aspx.designer.cs
file and to regenerate it, right click on the Project (WebApplication2
) and Choose 'Convert To Web Application
' this will regenerate your About.aspx.designer.cs
file.
Upvotes: 6
Reputation: 6330
try to clean your solution and rebuild it,most preferably this problem is because of wrong Inherits attribute in .aspx file
Upvotes: 1