Josh Cooper
Josh Cooper

Reputation: 191

asp label or <%= embedded code block

I'm recreating an older site and this time looking for inefficiencies. I have previously used a mix of both asp labels being populating server side and leaving embedded code blocks of <%=text here%> to display code retrieved server side.

<h4 class="page-title"> Profile Name - <asp:Label ID="lblName" runat="server" Text=""></asp:Label></h4>

and

<img class="profile-pic animated" src="<%=ProfilePicURL%>" alt="">

Which should I use going forward to ensure the best site performance?

Thanks

Upvotes: 1

Views: 54

Answers (1)

hardkoded
hardkoded

Reputation: 21597

I don't know if you will find a huge difference in performance there. But if we analyze how each solution works, we could say that <%= %> would be faster.

<%=%> is a shortcut for Response.Write. It's just writing an string into the StreamWriter, whereas a Server Control (an asp:label or an asp:image) has a Render process and a reconstruction phase on postback which is relatively more expensive.

Upvotes: 1

Related Questions