1

I have the following UserControl ASCX:

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="TestUC.ascx.vb" Inherits="Common.DataQuery.TestUC" %>

<script>
    function fcTest() {
        alert('<%=lblTest.ClientID%>');
    }
</script>

<asp:Label runat="server" ID="lblTest" Text="test" />
Testing constant: <%=MAXT%>
End of test

And the ASCX.VB:

Namespace DataQuery

    Public Class TestUC
        Inherits System.Web.UI.UserControl

        Public Const MAXT = 10


        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            lblTest.Text = " dd"
        End Sub

    End Class
End Namespace

Currently getting error on the <%=MAXT%> statement, saying it's not defined. Why?

igorjrr
  • 790
  • 1
  • 11
  • 22
  • did you ever figure this out? I am having the same issue.. I literally added a new default ascx page, and added a public property IsTest as Bool, and I cannot see if from the ascx <% vb.code.goes.here %>. I don't get why – Nyra Sep 08 '21 at 20:41

1 Answers1

0

That's because of the Namespace. Remove the begin namespace and end namespace and try. It would work. If you still need to give a namespace refer to this post how to specify one - How to specify a namespace for an ASP.net UserControl?

Community
  • 1
  • 1
  • I followed this post, it works but can't access the constant. – igorjrr Feb 03 '15 at 20:48
  • I believe that's because your .ascx says Inherits="Common.DataQuery.TestUC" and your code-behind says Namespace DataQuery. they both should be consistent. else, the code perhaps wouldn't even compile. – Srikanth495 Feb 03 '15 at 20:56
  • 1
    I created a new Web User Control (with default settings, no explicit namespace, etc.). Added the constant and tried to use it on the ASCX. No go. – igorjrr Feb 03 '15 at 21:19