What is the difference in doing this:
<a href="<%=this.GetUserProfilePermalink()%>"><%=this.GetUsername()%></a>
and this:
<a id="hlUser" runat="server"></a>
in codebehind:
hlUser.HRef = GetUserProfilePermalink();
hlUser.InnerText = GetUsername();
I noticed my codebehind is more readable doing it first way because I moved all assinging to markup however if I miss something somewhere it’s hard to find mistake due to “too many character in literal” error.What is the difference and what is the preferable way of doing this?
With the second way of doing it, you will create a Hyperlink object on the server, set some properties on it and then when the page is at the Rendering state it will use the object to render the hyperlink in HTML.
With the first way, you simply emit strings using the Response object, there is no Hyperlink object created on the server.
Even tho the first method is usually more lightweight, the second method has a lot of advantages. For example since you have an object on the server that Renders itself, it can be aware of which browser it is currently rendering it self to, and use different rendering techniques for different browsers so it works everywhere.