Reputation: 5312
I have defined a variable in page Test.aspx.cs, public string TestText = "Select";
I want to use it in the page Test.aspx, <asp:LinkButton ID="lbAccessories" Text="<%=TestText %>" runat="server" CommandName="Select">
But the aspx page doesn't recognize the variable, in firefox it shows <%=TestText %>, and in IE7 it shows nothing.
Does anyone know where is wrong and how to show the variable?
Thanks
Upvotes: 0
Views: 93
Reputation: 887215
You cannot use <%= .. %>
expressions to set proeprties of server-side controls.
(this has nothing to do with the field)
Instead, you can set the property directly in the code-behind:
lbAccessories.Text = "Hi!";
EDIT: You can use databinding syntax: (with a #
)
<asp:LinkButton ID="lbAccessories" Text="<%#TestText %>" runat="server" CommandName="Select">
Upvotes: 3