470,631 Members | 1,994 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,631 developers. It's quick & easy.

asp:Label vs asp:Placeholder

In terms of disaplying text on the server side, which one is the better choice - an asp:Label or an asp:Placeholder?

The only difference between the two that I know is that label puts a <span> tag around it's contents. Is there any other difference between the two, particularly performance-wise?

Edit: Never mind a Placeholder cannot be used to hold text directly...I was probably thinking of something else =|
Feb 24 '09 #1
3 5523
9,735 Expert Mod 8TB
That was going to be my first response.

If you simply want to display text, and you don't want to have control over the style of this text, then you can use a Localize control instead of a Label. The Localize control will display the text instead of displaying it between <span> tags.

If you need to be able to control style of this text (colour, font, size, whether it's displayed on top of something or as a block) then you should use a Label. You can set the style of a Label control and when it's rendered the <span> tag will contain this style. The Localize control doesn't have this option because it just outputs text in the location that it's placed on the asp page.

If you don't want your text to be in a <span> tag, then consider placing a Localize control within a Panel. This will place the text within a <div> tag instead (Panels are rendered as HTML <div>s).

You have so much flexibility....the Localize control lets you dynamically set the text where you want it to appear. It can also be use along with .resx (resource) files to provide support for multiple languages/cultures.

Feb 24 '09 #2
Thanks Frinavale for the very detailed explanation :)

One question though, if I am to use localise control is there still a way to write the text if we don't know what the text is? (say if we need to grab it from a database). From what I know if we don't "runat=server" something, then we can't really control it (except the style)...
Feb 25 '09 #3
9,735 Expert Mod 8TB
That's exactly what the Localize control is for.
It has a Text property that you can set after retrieving it from a database or other resource. All .NET controls must have the runat="server" set...otherwise they wont work.

PS you cannot set the style for a Localize control....see the the explanation I gave before for reasons why.
Feb 25 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Chris Ericoli | last post: by
2 posts views Thread by Brett Robichaud | last post: by
5 posts views Thread by studio60podcast | last post: by
6 posts views Thread by David Colliver | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.