Showing posts with label stuff. Show all posts
Showing posts with label stuff. Show all posts

Saturday, March 24, 2012

Text property values in Textboxes in ASP.NET

I have a website designed where users can enter a large amount of data into a mutlirow textbox. This can be stuff that has line breaks and such. The user can enter this information and it looks OK if I retrieve it from my SQL Database. When I retrieve it into a Windows Forms text box...it looks rather garbled. Is there a way to make them both look the same? I fear that if users muck with the values in my Windows Form support app, it will screw up the display for the web users.

Line breaks on an HTML page can only be achieved by using the <br /> tags, therefore a piece of text with paragraphs will just run together when it is pulled from the DB to the web page. What I do to fix this is I created a function called FormatHTML() that takes a string input and replaces all carriage returns with a "<br />" tag. The function does something like this...
TheString.Replace(CHR(10), "<br />")
You'll need to import Microsoft.VisualBasic to do that.


But the text from the HTML text boxes is not returning HTML tags in the text...actually it appears to be ASCII or something like that. That is what is baffling. To add to my story. I took a text box in Windows Forms on a record that was added from the web. Made complete changes in the multi line text box and saved it. When I re-opened it it looked like it got changed again and had little boxes where line feeds and carriage returns would be and munged it together into a single paragraph.

In SQL Server these text fields are bunched together and where carriage return and linefeeds would be it shows boxes. So if I create these text values in multiline text boxes on the web they look normal like this:
Benefits

This has the following values:

1. Data
2. Data 2
If I open up that value after it has been stored in the database it is all mashed together with boxes for carriage returns and linefeeds. If I edit it in a Windows Forms text box and make it look normal, and then submit that back to the database. The web looks like it does above but going back into the Windows Form text boxes returns it to the funky display. What is up with this??


Nobody??

text to html

I have a text box on my website. How do I convert that text to html? The reason I want to do this is because I want <br> and stuff inserted once a user submits the text...

Can someone help me out please?I think I didn't explain myself well enough..

I have a textbox and when people type something out like this:

***************
This is my first line

This is my second line
***************

once I pull it out of a database, I want it to be displayed the same way... So it is displayed the way I type it out, like any of the posts on this board.

Can someone please help?
Assume that your text is stored in myString
If u want to convert it to html, use server.htmlencode(myString), it will convert sth. like "<" to "<". But it can't automatically generate <br>. So you have to use replace to do that

Finally, you can use
replace(server.htmlencode(myString), vbcrlf,"<br>")
BTW, basically, I will keep the original text in database, only encode them when output.
Why I do like that? Because when you want to update it, the html code will also be shown on the textbox for update, it confused the user much. So you'd better do the encoding in output, not do it when inserting it into database.
string temp = TextBox1.Text.ToString() + "<BR>";
Response.Write(temp);

that will do the trick
Thanks, got it working now...

Though there's a different way to encode it as html and stuff...
Thanks for the suggestion rgao906. It's a good idea
Lomex if you out three how do you do it?

when I used textbox.text i get a whole string like this:

Line 1. Line2.

I tried the above it doesn't insert the necessary <br
please help!