Why is TestString is always empty when I try to output it into my Label?
Base class for all asp.net pages
public class PageBase : System.Web.UI.Page
{
protected string TestString { get; set; }
}
protected override void OnPreInit(EventArgs e)
{
TestString = "test string";
}
asp.net page that derives from PageBase and uses a master page.
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Label ID="lblContent" runat="server" Text="<%# this.TestString %>" />
</asp:Content>
EDIT
The code below doesn’t actually work—I tested it, just not well. What OP was really looking for was:
I think you need to change this
to this
<%# just runs code, but doesn’t output anything. <%= will output whatever is inside those tags.