1

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?

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

Just to be a little more clear, variables need to be declared at the class level, not the method level.
Thanks Chris Haas. I did mean that. Also the minimum visibility of the variables should be protected level too. Should not be private.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.