Can somebody please explain this to me:
I have a label and I want to be able to set the Text property by calling a method in the aspx file. It works fine if I set the property in code behind, but I really want to set this property in the aspx file.
I have tried a couple of things, but what I expected to work was this:
<asp:Label ID="Label1" runat="server" Text=<%# GetMyText("LabelText") %> />
I get no errors when doing this, but my method is never called and the Text property is left empty.
Is it not possible to set property values to server side controls directly in the aspx without using resources or use hard coded values?
Update: My first try was:
<asp:Label ID="Label1" runat="server" Text=<%= GetMyText("LabelText") %> />
But that results in the following error:
Server tags cannot contain <% ... %> constructs.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…