tags:

views:

76

answers:

2

I have a method that sets the text for a label, and I'd like to use it to display several lines of text. Is it possible to insert a character into the text for the label to do this?

+2  A: 

Normally a simple <br/> tag will do it!!

martani_net
Right, but the function I'm calling simply sets the text for the label. I'm trying to avoid adding multiple labels. Is that possible?
Mike Pateras
If the function you're calling doesn't escape the text, then putting the literal characters for the break tag in there will do it.
Anon.
+1  A: 

You have a few choices. If you can trust your callers, you can allow formatted text to be passed into the parameter (so someone can pass "<br />" as part of the label text. If you can slightly trust them, you can still allow that one particular piece of HTML to come through while disallowing others, but you might want to put the intelligence in your function to limit how many breaks can come in one label.

Another (more obscure) choice would be to designate some other character or sequence of characters that you know will never appear on a label to indicate a break (e.g. "#NEWLINE"), and have the function substitute "<br />" wherever that occurs.

Joe Mabel
That was my problem. I was using the new MVC2 auto-encode syntax (<%:), and it wasn't processing my break tags. Your comments on trusting my callers clued me in. Thanks, all!
Mike Pateras