Visual Studio .NET 2005 reports false error

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
 
T

tofu.captain

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.
 
G

Guest

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
 
T

tofu.captain

i actually did that and i get an error that the control is already
declared. which, doesn't make sense...
 
Joined
Mar 12, 2007
Messages
3
Reaction score
0
Hi,

I have exactly the same issue, causing quite a bit of trouble - did you manage to find a solution?

Thanks.
Russ


tofu.captain said:
i actually did that and i get an error that the control is already
declared. which, doesn't make sense...

Peter wrote:
> 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
>
>
>
>
> "tofu.captain" wrote:
>
> > 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.
> >
> > Chicagoboy27 wrote:
> > > try
> > >
> > > lblFoo.Text = "this works";
> > >
> > > txtFoo does not exist in your project.
> > >
> > >
> > > tofu.captain wrote:
> > > > 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

> >
> >
 
Joined
Mar 12, 2007
Messages
3
Reaction score
0
Aarggh! At some point I made a "Copy of page.aspx", which resulted in a namespace or class name clash, which was reported as being in "page.aspx".
Crikey.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top