0

I have created a new Web project (.Net 3.5) and I've removed the original Default page in favour of creating a Master page and then recreating a Default with Master page. All worked lovely. Now, when I add my controls inside of the ContentPlaceHolder on the Default page, I get compiler errors when I try to access the controls from the CodeFile:

Error 4 '_Default' does not contain a definition for 'FirstName' and no extension method 'FirstName' accepting a first argument of type '_Default' could be found (are you missing a using directive or an assembly reference?)

My declaration of the control:

<asp:TextBox runat="server" ID="FirstName" />

Any ideas?

EDIT

Page declaration:

<%@ Page Title="" Language="C#" MasterPageFile="~/Master/MasterPage.Master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

Code-behind:

string firstname = FirstName.Text;
Neil Knight
  • 47,437
  • 25
  • 129
  • 188
  • Perhaps a stack trace is in order? – krs1 Mar 29 '11 at 16:26
  • Code-behind? We need to see the class declaration in the .aspx.cs as well as the @Page tag. – n8wrl Mar 29 '11 at 16:27
  • Also, what is "FirstName" embedded in? Is there some other container (like a repeater or grid) that you have placed it into? It might help if you put your entire default.aspx page in pastebin.com – NotMe Mar 29 '11 at 17:22
  • Firstname is contained within a table, but this code is copied from another site I have made and its working. – Neil Knight Mar 29 '11 at 17:29

1 Answers1

1

I managed to get this working by changing CodeFile to CodeBehind.

Working:

<%@ Page Title="" Language="C#" MasterPageFile="~/Master/MasterPage.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_Default" %>

Not working:

<%@ Page Title="" Language="C#" MasterPageFile="~/Master/MasterPage.Master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

Neil Knight
  • 47,437
  • 25
  • 129
  • 188