简体   繁体   中英

vb.net passing variable from .aspx.vb to .aspx javascript variable

How do I pass a variable defined in .aspx.vb to .aspx.

I've tried this in the .aspx.vb:

Partial Class show_zoos
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'database logic

Dim postcode As String = an.Postcode
 End Sub
End class

And this for priting it out in the .aspx:

var postcode = '<%=postcode%>'

I got the following error:

'postcode' is not declared. It may be inaccessible due to its protection level.

What am I doing wrong?

postcode needs to be min visibility Protected.

Public postcode As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        postcode = "ABCD"
    End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM