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?
BenMorel
36.9k52 gold badges208 silver badges339 bronze badges
asked Jan 11, 2011 at 13:56
1 Answer 1
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
answered Jan 11, 2011 at 13:57
2 Comments
Chris Haas
Just to be a little more clear, variables need to be declared at the class level, not the method level.
KBBWrite
Thanks Chris Haas. I did mean that. Also the minimum visibility of the variables should be protected level too. Should not be private.
lang-vb