Connecting Tech Pros Worldwide Help | Site Map

Control does not exist in the current context

Newbie
 
Join Date: Sep 2007
Posts: 21
#1: Jul 4 '09
G'day,

I have encontered what appears to be a common problem, but unfortunately the typical solution i have found has not worked for me.

I have just copied the files from an "ASP .NET Web Site" to an "ASP .NET Web Application" because i have learned about the differences and have decided to move to the latter. I simply copied and pasted all the .aspx (with respective .aspx.cs code-behind files) and some other files such as scripts etc into the "Web Application". I have also added the same references to class libraries I had in the "Web Site".

When I come to compile the "Web Application", I get errors saying that controls "cannot be found in the current context". I did not get these errors in the "Web Site" and the common problem apparently is that there are backup files or duplicate partial classes, which i'm certain is not the case for me...

One example is that I have an ASP:PlaceHolder in header.aspx as follows...

<asp:Placeholder runat="server" ID="headermenuholder">

...but i get the error "The name 'headermenuholder' does not exist in the current context"

I would be VERY greatful if someone could give me their opinion! :)

Best Regards,
Chris
Newbie
 
Join Date: Sep 2007
Posts: 21
#2: Jul 4 '09

re: Control does not exist in the current context


Sorted.

Turned out i wasn't aware that in "ASP .NET Web Application" projects there needed to be both .cs and .designer for each page. I created a new page by going to add item and the correct .designer page was created, so i copied the code from the old version, deleted the old version and recompiled and it worked!

Thanks anyway :)
Newbie
 
Join Date: Sep 2007
Posts: 21
#3: Jul 4 '09

re: Control does not exist in the current context


Even Better!

Right click on the file and choose "Convert to Web Application" - feel a bit silly now!

Thanks
Newbie
 
Join Date: Aug 2008
Posts: 17
#4: Jul 5 '09

re: Control does not exist in the current context


ok, u got it, and nice to share with us
Newbie
 
Join Date: Nov 2009
Posts: 1
#5: 1 Week Ago

re: Control does not exist in the current context


Even silly things are great for unknown like me ... Thanks a lot .. I too had probelm in converting the website to web project

Thanks to cebellew !!!
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#6: 1 Week Ago

re: Control does not exist in the current context


It's good to know how you solved your solution.
I didn't realize that you can see this error in the case when the .designer file is missing (normally this file isn't missing because it's typically automatically generated for you by Visual Studio....I can see how it would be a problem if it were missing).

Usually when this type of error shows up someone is trying to use something that they aren't allowed to use in the Global.asax file.

Well, at least that's when I encountered this error.

The Global.asax file is a tricky thing. In some methods things like Session are available and then in other methods it is not. It's a little confusing when you first start using the Global.asax but once you realize what it's for things start making sense.

-Frinny
Reply