After putting a textbox on my page when I compile it I get the above error:
\'txtName\' is not declared. It may be inaccessible due to its protection level.
I've gotten this error when the class in the code behind doesn't specify Public
. Try this:
Partial Public Class signup <-------------Make sure the Public keyword is there
Inherits System.Web.UI.Page
...
End Class
Another possible scenario is if the class name in the Page.aspx.vb file differs from the class name in the Page.aspx.designer.vb file. These need to be identical.
I had a similar problem after adding controls to a web sete originally written in VS 2008 .Net 3.5 to VS 2010 .Net 4 After adding controls, I got the same error. When I looked at the .designer.vb file for the page, the added controls were not there. The problem was resolved by just adding the controls to the bottom of the file like: Protected WithEvents lblApprove As Global.System.Web.UI.WebControls.Label
This is what happened at my case.
-I have declared the variable at behind code
Protected Friend sMessage As String = ""
-Then the aspx : <%=sMessage%>
this case appears (visual studio 2015 - asp webform project)
Then I try to :
-clean solution
-Rebuild
Then the problem is gone
If the clean solution and rebuild does not work
try to clean the obj directory
If the variable is asp component
make sure runat="server" at the aspx file
May be this is missing in the textbox declaration:
runat="server"
Ok, I have this resolved now. It was becuase I had renamed a copy of the .aspx file and which still using the newer versions code behind file.
The code behind file was looking for txtName.text but on the older version of the .aspx file txtName didnt exist!
I have excluded the older version of the page from the project and it appears to run ok now.
Thanks everyone for you help.