kpg
kpg

Reputation: 671

added asp control gives error 'is not declared. It may be inaccessible due to its protection level.'

VS 2010 VB.NET Website project

On a masterpage of a website any controls I add to the master page aspx file gives the compile error: 'xxx' is not declared. It may be inaccessible due to its protection level.

This is for any new control I add, like an asp:button or an asp.panel, or a div with runat='server'.

In VS 2010 on the code behind the added controls are accessible, intellesense works, everything appears just fine, but when I compile I get a generic failed to compile error, but VS lists no errors, if I look at the build output I see the error above.

If I do not reference the added controls in codebehind the site will compile and the controls will be on the screen.

So whatever 'hidden' file VS has must be out of sync with the aspx file, problem is I see no such files in the project folders.

I did copy the master page a few weeks ago and rename it as a backup, but I edited the original not the copy. Still this may have caused the problem even though I just recently discovered it. It is possible I had not actually added any new controls that were referenced in the codebehind so I may not have noticed the problem.

How can I resolve this problem - is it possible to rebuild or resync this 'hidden' file?

I suppose I could create a new master page and copy the code over it that would work, but I have a lot of other pages referencing this master page...what a mess.

Upvotes: 1

Views: 3628

Answers (2)

DPP
DPP

Reputation: 1

Space constraint(low disk space) on drive was giving this vague message.

..'is not declared. it may be inaccessible due to its protection level.'

Resolved by creating space on drive.

Upvotes: 0

Duston
Duston

Reputation: 1641

In the page declaration, change CodeFile to CodeBehind (or vice versa.)

Check this link: CodeFile vs CodeBehind

Whether it is a Web site or a web application affects how the reference to the code file is stated. (BTW, it's a web application if there's a .vbproj or .csproj file.)

Upvotes: 1

Related Questions