* is not declared. It may be inaccessible due to its protection level
I've got a problem with one of my web forms pages.
this is how it started. I needed to completely revamp a page, I renamed the old pages default.aspx.vb.old and default.aspx.old and created brand new default.aspx and default.aspx.vb pages
every time I add a control to the aspx page and try and reference it in the code behind, I get the error 'lblError' is not declared. It may be inaccessible due to its protection level
'lblError' is not declared. It may be inaccessible due to its protection level
Page decalaration
<%@ Page Title="" Language="VB" MasterPageFile="~/_Masters/Principle.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Magazine_Default" EnableViewState="false" %>
Label control in Default.aspx
<asp:Label ID="lblError" runat="server" CssClass="cError" Visible="false" />
Default.aspx.vb Code Behind
Partial Class Magazine_Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lblError.Text = "There was a problem retrieving the magazines, please try again later"
End Sub
End Class
the page works, but visual studio will not build because it insists there is an error.
I thought it might be something up with my visual studio, like cache or something, so i nuked any temp files relating to the project.
and this morning a colleague did a git pull and has the same problem, errors are there, refuses to build but the page works.
The project itself is a website project, so there's no designer files where I can change the access modifier of the control.
I have also tried creating a new file, using the web form scaffolding that visual studio provides through add->web form
, which has all the correct page directives in the .aspx and correct class declarations in the .aspx.vb, and it still does it.
There is also no red squiggly line under lblError.Text
When I create a new page in the different folder, it doesn't happen.
As you renamed old default.aspx page, you need to rename its class too. Generally when you rename aspx page, it will not rename class name automatically. So you need to do that manually.
So for default.aspx page,
Inherits="Magazine_Default_Old"
And for default.aspx.vb page,
Partial Class Magazine_Default_Old
This will solve issue.
链接地址: http://www.djcxy.com/p/65218.html上一篇: 由于保护级别而变得不可访问