0

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.

mrblah
  • 99,669
  • 140
  • 310
  • 420
  • 2
    The title asks how to insert a space. The question asks how to chop off the text if it contains a space. Which is it supposed to be? –  Aug 24 '09 at 15:56

4 Answers4

2

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
  • 242,243
  • 40
  • 408
  • 536
0

Unless I am over-simplifying the problem:

overflow: hidden;

should do the trick.

Yuval Adam
  • 161,610
  • 92
  • 305
  • 395
0

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

apiguy
  • 5,282
  • 1
  • 23
  • 24
0

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

DanDan
  • 10,462
  • 8
  • 53
  • 69