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?

BenMorel
36.9k52 gold badges208 silver badges339 bronze badges
asked Jan 11, 2011 at 13:56

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
answered Jan 11, 2011 at 13:57

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

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.