Visual Studio .NET 2005 reports false error

  • Thread starter Thread starter tofu.captain
  • Start date Start date
T

tofu.captain

I'm using Visual Studio .NET 2005 with a C# Web Application project. I
have an ASPX page that uses a MasterPage file for a general site
layout. That works just fine, but when I run a compile of the ASPX
page (say default.aspx) with something like:

<asp:Label id="lblFoo" runat="server" />

and have it's codebehind have:

protected void Page_Load(object sender, EventArgs e)
{
this.txtFoo.Text = "this works";
}

However, when I run a compile, the Error List reports that:
'Default' does not contain a definition for 'txtFoo'

when clearly there is. The problem is that the project compiles and
runs fine, but the error list is reporting an incorrect error. Does
anyone else have a similar problem with VS.NET 2005? Is this a bug in
the IDE?

Some added notes:
- I do have multiple Default.aspx across my project, but they are in
different folders and I have checked that all referencing paths are
correct.
- I did copy & paste some code from a different page into this ASPX
page, and started noticing this bug, but I have commented out such code
and still get this problem running the above example. Is there a bug
with copying & pasting code from another ASPX page that runs something
similar to what I have above?

Thanks so much
 
oops, actually what i have is that, i just wrong my example in this
topic wrong. but the issue still stands.

so what i have is:
<asp:TextBox id="txtFoo" runat="server" />

codebehind:
protected void Page_Load(object sender, EventArgs e)
{
this.txtFoo.Text = "this works";
}

sorry for the misprint.
 
I think the issue here is that VS 2005 has the concept of partial classes.
The designer class that's "supposed" to have the declarations of your page's
controls isn't getting one, e.g. "protected Label lblFoo;"
You can either supply one yourself by typing it in, or sometimes if you
switch from design to code view and then back again, it gets itself "back
together".
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
 
i actually did that and i get an error that the control is already
declared. which, doesn't make sense...
 
Back
Top