PDA

View Full Version : Visual Studio 2008 and code behind page not seeing controls


janetb
04-01-2009, 02:48 PM
This is hopefully just a setting I can't find, but I'm desparate. I'm starting out with Visual Studio 2008 with Ajax on a test website (I've been using VS2005 with IIS6). None of the controls are recognized on the code-behind page. If I open the old websites in VS2008 without converting, they still recognize controls fine.

Anybody know what I'm missing? Sorry, if I can't find it - I can't use VS2008.

Janet

vinyl-junkie
04-01-2009, 04:26 PM
I had something similar happen to me when I added an existing item (web form) into a test folder on my local machine so I could make some changes to it. To get the code-behind to recognize the page controls, I deleted the web form code and pasted back it back in. As I recall, I also did the same thing with the code-behind.

Really strange I should have to do something like that but it worked.

janetb
04-01-2009, 05:51 PM
Thanks vinyl,
Tried it, said it was updating, didn't work. Besides, have to do that on every page I create? I've got three dummy pages, none of them recognize controls or even the page in the code-behind.

SippyCUp
04-22-2009, 06:39 PM
Did you try setting the CodeBehind attribute in the @Control directive? I'm having the same problem. I did that and now IntelliSense recognizes the controls, but when I try to compile, it's still telling me the controls don't exist. Maybe setting CodeBehind will fix the whole thing for you. Who knows?

Budsy
06-10-2009, 01:27 AM
Just today I had this happen to a working web application (VS 2008-, ASP 3.5). The page has several standard controls that are not recognized in the code-behind. Here are some other symptoms:

(1) The page compiles fine when using 'build page'.
(2) The application will not compile without errors, such as the following:

error CS0103: The name 'xxxTextBox' does not exist in the current context

(3) Only the asp web controls are not recognized. AjaxControlToolkit, Metabuilders, etc., work fine and are recognized.
(4) It is possible to make intellisense work in an inconsitent way, and in the cs editor you can actually end up with...

myTextBox.Text = "hello"; // this line is ok, and intellisense works.
string Str = myTextBox.Text; // but this line shows error (underlined control name string) as control not recognized!! Intellisense will not work on the very same control name.

(5) As this problem arose it was intermittent. The site would fail to compile and give errors, but I could get it working again by flipping back and forth between source view and design view in VS, or by making a slight edit. Now I can't get it to compile at all.

(6) While the code-behind won't recognize the controls, you still can not add a control with the same name on the aspx page, either in design or source code mode. In source/design mode the controls are apparently recognized in the usual fashion.

This situation is ridiculous. My application is dead in the water. I've tried starting up fresh pages and starting from scratch, but no go.

Budsy

naterackers
08-05-2009, 10:29 PM
Has anyone found a solution to this problem? I am having the same type of issue also.
thanks

bugmenot
08-17-2009, 07:32 AM
Here might be a possible solution to the problem:

In your .ASPX file, your statement at the top of the page reads something like this:
<%@ Page Title="" Language="VB" " CodeFile="PAGENAME.aspx.vb" Inherits="NAMESPACE" %>

That "NAMESPACE" must match exactly with what is in your .VB or .CS codebehind file.

Your codebehind should look something like this:

Partial Class NAMESPACE
Inherits System.Web.UI.Page

If your names are off, you will not be able to access your controls from the codebehind and youll get the error message youre receiving.

A common cause of this problem is renaming or copying/duplicating your aspx page then renaming it back.. your codebehinds dont update correctly to the real class name.

Just a thought.