Search code examples
asp.netpropertiesdeclarative

How do I declaratively insert a property value of a page into it's rendering?


I would like to have an aspx page that contains something like....

<form id="form1" runas=server >
    Hello <%= Me.UserName() %>
</form>

and a code-behind something like...

Public Class Somepage
    inherits SomeOtherPage
    Private Readonly Property UserName() as String
    Get
        return "Rory"
    End Get
    End Property
End Class

I have tried this code but the aspx errors claiming that UserName is not declared.

What is the proper way to do this?


Solution

  • Mark the property as Protected, not Private.

    Protected Readonly Property UserName() as String    
         Get        
              return "Rory"    
         End Get    
    End Property