views:

88

answers:

4

Hi,

I have a user control in my asp.net web project.

It displays the title of a blog post. If the title is too long, it will stretch the wrapped table and ruin the page layout.

Is there a way I can chop the text after 40 characters IF the text doesn't contain a space in it?

How would I check for the existance of a space anywhere, and if not exist insert a space.

I'm looking for the 'best practise' as I'm sure this is a common problem for web apps.

A: 

Unless I am over-simplifying the problem:

overflow: hidden;

should do the trick.

Yuval A
but then the text is hidden?
mrblah
+2  A: 

The best practice in this case would be to re-visit your page layout design.

It sounds like you've designed something that is a little too in-flexible for the web. The user always has the option to resize the browser...and that could definitely break your layout as you describe it here.

Forcing their hand is a poor user experience.

Creating something flexible that behaves gracefully no matter the length is the better option...

Justin Niessner
A: 

The <wbr/> tag was designed for this purpose. There are also some other html entities that can help with this. Essentially it suggests to the browser that this would be an ok place to break if the line gets too long.

You can read more here:

http://www.quirksmode.org/oddsandends/wbr.html

free-dom
So I should insert that tag after x characters?
mrblah
Yes. Determine a threshold of characters that fits your site layout.
free-dom
A: 

TextFormatFlags may help you. You may want to do something with WordEllipses or WordBreak.

DanDan