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.
Related
Why doesn't my RDLC display the HTML content? I have saved encoded HTML formatted text in an Nvarchar field in the sql table like given below:
<p><strong>ANDSLASKNDKLSNALNDKLANDLANND</strong></p><pre><pre lang="c#">
Even in RDLC, I have checked the HTML- Interpret HTML tags as style option but still it doesn't display the formatted output.
Why?
As discussed in comments, only subsets of HTML can be rendered (to protect it from html injection). Instead of using <strong> you will have to use <B> to define bold text.
When you import text that contains HTML markup, the data must always
be parsed by the text box first. Because only a subset of HTML tags is
supported, the HTML that is shown in the rendered report may differ
from your original HTML.
The following is a complete list of tags that
will render as HTML when defined as placeholder text:
Hyperlinks: <A href>
Fonts: <FONT>
Header, style and block elements: <H{n}>, <DIV>, <SPAN>,<P>, <DIV>, <LI>, <HN>
Text format: <B>, <I>, <U>, <S>
List handling: <OL>, <UL>, <LI>
Taken from this: http://msdn.microsoft.com/en-us/library/cc645967.aspx
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 am developing a windows application using c#. I am loading a file (html, txt, xhtml) to the text box. I want to test the occurrence of following cases in my text box.
,(comma) with closeup text (ex. text1,text2)
.(dot) with closeup text (ex. text1.text2)
:(colon) with closeup text (ex. text1:text2)
,(comma) with closeup ' i.e (left single quotation mark)
"(doublequote) with closeup text
'(single quote) with closeup text
</i> with closeup text (ex. </i>text)
</span> with closeup text.
For all the occurrences of the above condition I want to highlight the particular found text in the textbox. I am trying to use the regular expression. I am inserting all the cases in the array list and checking one by one. For the first case if the text in the textbox is like hjhdf, dfsjf then it will show the message box, if any text before and after this particular text then it will not show the messagebox.
string regexerror = wordToFind;
Regex myregex = new Regex("^[,]*[a-zA-Z]*$");
bool isexist = myregex.IsMatch(rtbFileDisplay.Text);
if (isexist)
{
MessageBox.Show("Hi");
}
At the moment you're only matching the beginning of the entire text with ^. You need to get it to match the beginning of a line instead.
Look at this link: http://msdn.microsoft.com/en-us/library/yd1hzczs.aspx. This explains use of the MultiLine property:
myregex.MultLine=true;
This should do the job.
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 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