aspx页面上的变量,表示未声明它

时间:2016-04-12 09:04:03

标签: asp.net vb.net compiler-errors visual-studio-2015

我正忙着对旧的VB.Net/ASP.Net解决方案进行维护。 相当多的.aspx页面引用了代码背后的变量。在工作时,这些都显示为错误,但代码确实编译(使其不重要,但非常烦人,并且很难找到实际错误)。

我尝试过protected和私有variables

我做了一个测试页面,以表明问题。

TestForm.aspx

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="TestForm.aspx.vb" Inherits="EGS.TestForm" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <%=message %>
    </div>
    </form>
</body>
</html>

TestForm.aspx.vb

Public Class TestForm
    Inherits System.Web.UI.Page
    Protected message As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        message = "Hello!"
    End Sub
End Class

错误列表

Error | BC30451 | 'message' is not declared. It may be inaccessible due to its protection level.

运行

Hello!

有没有办法让Visual Studio(2015,如果有所作为)看到这些。它们工作得很好,就像我说的那样,它非常烦人。

1 个答案:

答案 0 :(得分:0)

使用public修饰符声明message变量

Public Class TestForm
    Inherits System.Web.UI.Page
    public message As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        message = "Hello!"
    End Sub
End Class