views:

89

answers:

1

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?

+3  A: 

Mark the property as Protected, not Private.

Protected Readonly Property UserName() as String    
     Get        
          return "Rory"    
     End Get    
End Property
TGnat
I forgot that aspx inherits from the Declared class rather than being partial with it... Man I feel dumb now :)
Rory Becker
The other way to do this, and in my opinion the preferred method that preserves encapsulation, is to use a label control and explicity set the text property of the label.
TGnat
Agreed. My example was vastly oversimplified. In reality I'm populating the value attribute of a number of htmlinput controls whose 'name' attributes must be fixed and therefore I cannot risk the name mangling which might result from using equivalent ASPx controls :)
Rory Becker