views:

45

answers:

2

I have:

Page.aspx
Page.aspx.vb
TestClass.vb

I'm trying to access a shared property of the TestClass class from the Page.aspx.

This code works fine:

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

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

</script>
</head>
...

But when I try to access a shared property of TestClass, I get an exception:

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

ERROR BC30451: Name 'TestClass' is not defined.

This is the class:

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
A: 

It's not quite clear but is your class in a namespace? You may need to import the namespace into your aspx file.

<%@ Import Namespace="MyNamespace" %>
Mark
It not worked... the same error again.The "TestClass" class is not the code-behind of the page. I have:Page.aspxPage.aspx.vbTestClass.vbI'm trying to access a shared property of the TestClass class from the Page.aspx.
Fernando
A: 

You need to create a new instance of TestClass. Try something like this:

<script language="JavaScript">

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

</script>
mattbasta