I guess I'm missing something here, but I can't find a way to pass a simple variable from my code behind file to the .aspx page.
In code behind I have:
Dim test As String = "test"
and in my aspx page I try: <%=test %>
that gives me the following error:
Error 2 'test' is not declared. It may be inaccessible due to its protection level
Am I forgetting something here?
Declare test
as a property (at the class level) instead of a local variable, then refer to it as you currently do in your markup (aspx).
VB.NET 10 (automatic properties):
Protected Property test As String = "Test"
Pre-VB.NET 10 (no support for automatic properties)
Private _test As String
Protected Property Test As String
Get
Return _test
End Get
Set(value As String)
_test = value
End Set
End Property
With the property in place you should assign a value to it directly in your code-behind.
Use the protected modifier.
Protected test As String = "test"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With