This is stemming from a bad answer I gave last night. The curiosity as to why one method works and not the other is bugging me and I\'m hoping someone smarter than me can g
Using <%= %> is equal to putting Response.Write("") in your page. When doing this:
<%= GetMyText("LabelText") %>
The ASP.NET processor evaluates the control, then when rendering, it outputs the control's contents & calls Response.Write where it sees <%=.
In this example:
You can't use Response.Write("") on a Text attribute because it does not return a string. It writes its output to the response buffer and returns void.
If you want to use the server tag syntax in ASP.NET markup you need to use <%# %>. This combination of markup data binds the value in the tags. To make this work, you'll then need to call DataBind() in your page's Load() method for it to work.