Monday, March 26, 2012

HTML Encoding CRUD data for later display

Hi All,

This is a problem that I have resolved before by writing my own library but I would like to know if there is a better way to do this. The issue with using the library I wrote is that there is quite excess encoding that get stored in the database that I would like to avoid.

I am dealing with content entered on a fron-end using HTML textbox tag into a database and which is later read by a backend system using .NET 2.0 controls. On the backend I return write resposnes to data entered in the from end using TextBox control and I also display them using Label control.


My problem is dealing with the fact the \n \r entered do not seem to be encoded when I display data in Label Tags i.e. everything gets displayed in one long line. Is there an inbuilt way in .NET to solve this. I need to possible solution that would work in both .NET 2 and 1.1 as my solution spans both frameworks. On the Net 1.1 side I actually use HTML tags (non asp.net) so I somehow have to be able to convert my \n to <br/> and so on...


TIA,

Tuka

Hi,

Based on your description, I understand that you need to escape the carriage return \r\n to <br/> using a build-in way of .NET framework. If there is any misunderstanding, please feel free to let me know.

As far as I know, there isn't a build-in method for you to do this conversion. The only way is to write your own library to change \r\n to <br/>. This can be done by either string.Replace or Regular Expression.

Hope this helps.


Thanks for your reply. I think you understood me exactly - I'll just adapt my existing library then

Cheers,

Tuka

No comments:

Post a Comment