Philip Stratford
Philip Stratford

Reputation: 4753

HTML Labels and Controls in ASP.NET Pages?

Just a general question that I've been wondering about for a while. I write a lot of pages in ASP.NET, and so all of my controls have tags beginning <asp:, and include runat="server", meaning that they're server-side controls. What I'm wondering is whether there's any advantage to using client-side controls rather than server-side controls when they don't need to be server-side.

For example, rather than having:

<asp:Label ID="lbl" runat="server" Text="This is a label" CssClass="labelclass" />

Would it be advantageous in any way (e.g. performance-wise) to instead use:

<label class="labelclass">This is a label</label>

?

Upvotes: 0

Views: 549

Answers (4)

mclark1129
mclark1129

Reputation: 7592

In addition to the server having to render server side controls, they also require an associated ViewState in order to be ping ponged back and forth between client and server. This results in larger requests, heavier loads, and longer load times for your pages.

Upvotes: 0

Pawan Nogariya
Pawan Nogariya

Reputation: 8990

Definitely there is a performance boost if we use client control rather than server control as server controls are parsed by asp server and it generates html for it and so it is an overhead.

Its not about how much performance but there is definitely a performance difference.

Server controls should only be used if they have to get modified on server side.

Upvotes: 1

Curtis
Curtis

Reputation: 103428

If they don't need to be server-side controls, use client side controls. This will make the rendering quicker as there is less code to convert.

I generally only use server-side controls if I'm going to be referencing the control in some way in my code behind file.

On a site note, its worth mentioning, an ASP.NET Label web control renders as a <span> element, and not a <label> unless AssociatedControlId property is used.

Upvotes: 2

Vlad
Vlad

Reputation: 2565

Only if there is no intent to modify or access label values on the server side. It will be slightly faster to use direct HTML as in this case ASP.NET won't have to spend time to parse server control to generate anything.

Upvotes: 2

Related Questions