Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What control can render text with carriage returns?
Message
From
06/11/2009 10:36:43
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01433564
Message ID:
01433576
Views:
39
Thanks for sharing several options.

I did NOT set TextMode="MultiLine", so I'll try that first, but I like the other ideas too.



>>A have a field in one of my database tables that contains text with carriage returns. I need to bind this (read only) to a UI control to show these comments to the user on the page. What control or technique should I use? I tried < asp:TextBox > with a wide width and tall height, but it does honor the carriage returns.
>>
>
>Textbox should work. Did you set it's TextMode="MultiLine"? I'd also set ReadOnly="true". It will automatically HTML-encode strings as well.
>
>This is basically just an HTML thing. Normally, CR's are ignored. You can handle this a few different ways in addition to Textbox. One would be to use the Literal control and embed your text inside of <pre> tags. Then the browser will render it as-is. ex.
>
>
>this.litField.Text = "<pre" + fieldValue + "</pre";
>
>
>Or, you can just transform some of the text before display by converting the CR's into a <br/> tag and using the literal control. You would want to HTML encode the text first, though.
>
>Ex.
>
>
>this.litField.Text = Server.HTMLEncode(fieldValue).Replace("\r", "<br/");
>
>
>I'm sure people have other ways they handle this as well.
>
>>Also, what is the proper data type to make this field in the table? Right now it is a type called "ntext", and I'm not even sure why it is that type. This data was given to me by the customer in Access, and I upsized it into SQL Server. I can change the type however I need to, so what is best for this case?
>
>ntext is SQL's unicode text-type. If it's a multilingual app, that's the correct data type. Actually, the new type should be nvarchar(MAX) since text/ntext is now deprecated.
Previous
Reply
Map
View

Click here to load this message in the networking platform