I have a textbox multiline for insert text in my db.
This text is viewed in a div, but without newlines.
How can I view the newline in my text?
thanks
Put your text inside <div><pre>... text ...</pre></div>. pre tag preserves line breaks.
Use the following:
myText = myText.Replace(Environment.NewLine, "<br />");
to replace newline characters with proper HTML line-breaks.
Best wishes,
Fabian
Related
Maybe some of you can help me with the following problem. I want some words bolded in a textbox(winforms).
I have a string _descripton variable containing some description text. For example:
“ this is a description of a \b car \b0………… ”. Im trying to replace the string format with richtextformat like:
string _makebold = _description.Replace("\b", #"{\rtf1\ansi \b").Replace("\b0", " \b0.}");
to get the following result: this is a description of a #"{\rtf1\ansi \b car\b0.}"……….
And finally setting the text property of the richtextbox1:
richTextBox1.Text = _makebold;
I cant get that specific word bolded in a richTextbox and textbox doenst work either.
can anyone help me with a solution?
Thanks!
You can use Rtf property of the rich text box control.
For example, the following text adds the text "This text is in bold." to an existing RichTextBox control.
See this MSDN link.
richTextBox1.Rtf = #"{\rtf1\ansi This is in \b bold\b0.}";
What I want to do is to fill it with text programatically.
webBrowser1.Document.GetElementById("textBox").InnerText = "foo";
This code works but some websites have a placeholder text. This code will not allow me to fill this as value but instead it as a placeholder text.
Strangely in some text box, it will be paste as value when there are a placeholder text. But some text box it wont.
Another scenario is that when it is innerText is placed as a placeholder text, all I have to do is click on that text box and write something next to it. This will act as a text box values.
Is there another way around this?
You need to set the value attribute of the <input id='textBox'> elment not the innertext.
webBrowser1.Document.GetElementById("textBox").SetAttribute("value", "text text text");
I have a text box on an html form that I set with a value from the server. But if the value contains an quotation mark, it breaks things. So I html encode it to produce the quote entity, but now this entity shows up in the text box on the page.
I want to insert html tag to a Database as a String and retrieve it back. after retrieved it ,I want to bind it in Grid.
as a example
String word = "<h1>This is Heading </h1> \n <h2>This is body</h2> \t This is after tab";
after I bind to the grid it should be
This is Heading(in a big font size)
This is body(in small font) - (tab space) This after tab
However this way is not working. It shows
<h1>This is Heading </h1> \n <h2>This is body</h2> \t This is after tab
word instead of applying real HTML behavior. I tryout with '\' special character removal but it remain same result.
Please help me.
Exactly which control are you using? Most of them will escape html like that for you, and to get it to be written 'as-is' you have to set a property.
If you're using GridView, then you can set the HtmlEncode on your BoundColumn to false.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.htmlencode.aspx
If you're using AutoGenerateColumns, see this SO thread: Prevent HTML encoding in auto-generated GridView columns
Saving into DB is not a problem, you can save directly the string into DB,But when displaying on UI you must use HttpUyility.HtmlEncode(), else it will invite Javascript Hacking.
But if you are entering data from WebPage, make sure Input Validations are turned off Else you will get XSS script attack error.
you can bind your text in literal control it will represent the actual HTML formatted text.
like :
ltrlMsg.Text="<div class=\"Message Success\"> Your Message has been sent successfully! </div>"
or you can bind in you grid too.
I have some user input that I am outputting to a label.
I have used HTML.Encode in order to show the input in the way the user entered it (ignoring as a html tag).
However, I have noticed that the user input like New Line are not using in the label. It's simply displayed as white space.
I've done this
msg.Text = msg.Text.Replace(Environment.NewLine, "<br />");
which seems to now be displaying the right input.
Is that the best way to do this? Or is there like a common method that can convert newLines, tabs, etc. all of the invisible formatting things into HTML tags?
I don't know of any other way. What I usually do (in case you have a single "\n" or a "\r\n" combo) is replace all "\r\n" first, then any single "\n" last.
lbl.Text = lbl.Text.Replace("\r\n", "<br />").Replace("\n", "<br />");
For tabs you can use 4 non-breaking spaces.:
lbl.Text = lbl.Text.Replace("\t", " ")
To preserve any spacing (as html will aggregate multiple continuous spaces into a single space) use:
lbl.Text = lbl.Text.Replace(" ", " ")//Replace every 2-space pair.
Remember to Encode your text first before adding in markup like <br /> that you intentionally want to render.
You could also use a TextBox, set it's MultiLine property to "true" and Enabled to "false" if you want to display the information with the original carriage returns without resorting to inserting markup. I think the label is the best choice though.
If possible, just use a Multiline Textbox instead of label.