1

我有:

Page.aspx
Page.aspx.vb
TestClass.vb

我正在尝试从 Page.aspx 访问 TestClass 类的共享属性。

此代码工作正常:

...
<head>
<script language="JavaScript">

    <% if System.Globalization.CultureInfo.CurrentCulture.Name.ToLower = "pt-br" Then %>
        alert('portugues');
    <% else %>
        alert('ingles');
    <% end if %>

</script>
</head>
...

但是当我尝试访问 TestClass 的共享属性时,我得到一个异常:

<% if TestClass.Idioma = TestClass.TipoIdioma.Portugues Then %>
    alert('portugues');
<% else %>
    alert('ingles');
<% end if %>

错误 BC30451:未定义名称“TestClass”。

这是课程:

Public Class TestClass

    Public Enum TipoIdioma
        Portugues
        Ingles
    End Enum

    Public Shared ReadOnly Property Idioma() As TipoIdioma
        Get
            If System.Globalization.CultureInfo.CurrentCulture.Name.ToLower = "pt-br" Then
                Return TipoIdioma.Portugues
            Else
                Return TipoIdioma.Ingles
            End If
        End Get
    End Property

End Class
4

2 回答 2

2

您需要创建一个新的TestClass. 尝试这样的事情:

<script language="JavaScript">

    <%
    Dim tc = new TestClass()
    if TestClass.Idioma = TestClass.TipoIdioma.Portugues Then %>
        alert('portugues');
    <% else %>
        alert('ingles');
    <% end if %>

</script>
于 2010-01-18T14:30:16.317 回答
0

这不是很清楚,但你的类在命名空间中吗?您可能需要将命名空间导入到您的 aspx 文件中。

<%@ Import Namespace="MyNamespace" %>
于 2010-01-18T11:55:03.410 回答