Click here to Skip to main content
15,749,352 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am trying to send a vb variable to Javascript using code behind. It's not something I have ever done before.

I am getting the error queryNoVb is not declared. It may be inaccessible due to its protection level in the aspx page.


What I have tried:

VB.NET code:
Public Class WebService
    Public Function queryNoForCodeBehind()
        Dim userId As Integer = Session.Item("uid")
        Dim groupId As Integer = Session("gid")
        Dim layers As New List(Of Object)
        Return getQueryNoFunction(Settings.Dif, userId, layers)
    End Function
End Class

Code Behind:
Public Class getQueryNoClass
    Inherits WebService
    Dim webServiceInstance = New WebService

    Public queryNoVb As Integer = webServiceInstance.queryNoForCodeBehind()
End Class

aspx page:
   function getQueryNo() {
       var queryNoImport = <%=queryNoVb%>;
Updated 25-Jul-19 1:50am

1 solution

Use a Hidden Field as described in this post - set value in javascript variable from code behind[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900