Wednesday, December 29, 2010

How to make your ASP.Net label multiline (how to wrap text in your label)


First off, sorry for the absence. Things got a little busy in life as well as work. Not to mention having to get up to speed on 2.0 in a big hurry. All good things, but it left less time for fun stuff.

With that said, I want to offer a little tip to help with formatting your ASP.Net pages. Getting a label to be multiline within a set width. Now many of you know this trick, but I always have to re-remember the trick every time I need it, so this post can be a reference for you as well.

The trick is actually this - Don't use a label. Use a textbox instead. Since all the controls inherit from the same base class, the text box and the label are very similar anyway. But only the textbox has the multiline capability.

Once you have the textbox on your page the trick is to make it look like a label for the end user. To do this you need to set the following properties (This is the part I can never remember):

Wrap = true; (obviously)
rows = {some number greater than 0} (I use the rows property rather than the height property as it tends to be earier to get the formatting right)
ReadOnly = true (makes sense, right)
TextMode = multiline (or there no real reason to wrap the text...)
BorderStyle = None
BorderWidth = 0

Those last two are actually VERY important, and here is why. They get rid of that pesky border that you see around text boxes. That border is a common visual signal to the end user that says "ENTER INFO HERE!". If you leave the border up expect a lot of phone calls from folks saying "The web page is broken. It won't let me enter text."

So use this in good faith. More controls soon. Even my first 2.0 controls.

2 comments:

Gary said...

Hi,

Who can I speak to regarding advertising today?

Thanks,

Gary

gary@socialreality.com

papayoung said...

asics gel lyte iii sale Holding a cheap cheap asics phone is love, so high-grade fine full-featured mobile phone for the first time personally seen, personally playing. It is said that this phone is a limited edition, asics gel lyte iii sale asics gel lyte iii sale there is no market price, is the sale the night before from a little girl's hand with a Mongolian got even fool, is not to talk about this with the sale of the phone asics tiger mexico 66 sale gave me.