Reputation: 11240
Lets say we have the following in the default.aspx file
<asp:Literal runat="server" Text="<%= TestMethod() %>" />
What needs to be defined in the default.aspx.cs file to make this work?
I tried to add a method called TestMethod
to the _Default
class which simply returned the string Test
, but it didn't seem to work.
Can anyone help?
Thanks,
AJ
Upvotes: 2
Views: 3514
Reputation: 14460
I think you can get the same result by doing this
In your .aspx
file
<asp:Literal runat="server" ID="ltr1" />
And in your aspx.cs
file
ltr1.text = TestMethod();
Upvotes: 2
Reputation: 164
Apart from the method being marked public
...
i think you could also remove the asp:Literal
altogether
example your code
<p><asp:Literal runat="server" Text="<%= TestMethod() %>" /></p>
could be
<p><%= TestMethod() %></p>
However if you are intent on using the Literal then please rather set it on page load.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.literal.aspx
Regards.
Upvotes: 4