Question

(Was: ASP.Net codebehind not finding controls on the web page)

I'm using VS 2008.

I don't know what secret switch I need to flip, or what trip wire I accidentally tripped over, but the last form I created in my project is misbehaving very seriously: the codebehind is apparently unable to find any of the controls that I have set up on the form. The codebehind file exists, but it generates compile errors on any references to the controls that are declared on the form.

The most obvious clue is that in the markup of the form, the first line is:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="UserSignature.aspx.vb"
  Inherits="EEI_App.UserSignature" %>

and the Intellisense has underlined the whole first line, giving me some stupid "could not load file or assembly" message, that it can't find a completely unrelated DLL that is plainly and visibly in my app folder, with the reference correctly set up.

At first the Intellisense was only underlining the "CodeBehind" setting, saying "File UserSignature.aspx.vb was not found." - then for some reason it started with this other message about the DLL, also.

Every other form in my project is compiling and working fine, and there are no obvious differences between this form and any other form.

I have tried opening and closing Visual Studio; I have tried rebooting - nothing makes any difference. Every new form I add to my project cannot communicate with its own codebehind - from the moment of creating the new file, the markup gives me the "File 'NewFile.aspx.vb' was not found" error!

Any ideas?

Thanks


I think I'm closing in on the problem. @MatthewMartin, you are definitely warmest so far.

It appears that the form.aspx.designer.vb is not being refreshed for some reason when I drop controls onto the form. I still have no idea why this is, but at least we're getting warmer!


OK, this is definitely the problem now, and I've renamed the question to reflect this: the fundamental issue is that my form.aspx.designer.vb form is not being refreshed when I drop controls onto the form. Any ideas at least for a workaround - how to force the designer to refresh?

Thanks!

Was it helpful?

Solution 5

OK, I found my own answer:

Commit all working code to source control, blow away the dev tree, get latest version.

Suddenly everything is working again. And it also solved my other problem of today.

I'll give credit for the answer to anyone who can work out what secret switch I flipped by blowing away my dev tree and starting again clean... :)

OTHER TIPS

You can force the aspx.vb.designer page to regenerate by deleting the text of the controls and immediately re-pasting it back into place.

Also check to see that the code behind page has a class of UserSignature and a namespace of EDI_App. Also depending on if you are using a web application/web project, the default namespace might be different. You can verify by creating a new file and looking and what the default pattern between the page directive and the class name declaration in the code behind.

Finally, if this was a converted 1.1 application, or a 2.0 application where the code behind doesn't say

partial class

, then you will be responsible for declaring all control references.

Have you renamed it? Changed the base/project namespace? In particular look at EEI_App.UserSignature - is that the correct name?

For simplicity, consider re-creating the page, copying the markup etc.

Try this :

<%@ Page Language="vb" AutoEventWireup="false" CodeFile="UserSignature.aspx.vb" Inherits="EEI_App.UserSignature" %>

Is it possible you've lost the reference to System.Web (or another important dll, maybe that dll you've mentioned)?
I usually get similar problems when I try to load a page or a user control to a dll solution. In fact, twice we've had to load the files we've received to a new project, and that solved it.

I had this exact same problem on Friday. It turns out that VS2008 isn't smart enough (using VSS as source control - I know, but it's what the client has) to check out the aspx, aspx.vb and designer.vb all at the same time in some cases. In my case, I was getting all sorts of strange behaviors, and of course Visual Studio, in trying to be "helpful" has no way to check out the designer.vb.

Solution is to check the page back in, then drop a control on the page and save (or delete a control - any action that will cause the designer.vb to get updated.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top