Click here to Skip to main content
14,455,062 members
Rate this:
Please Sign up or sign in to 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 2:50am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 2

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

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100