i have an text editor. save the data to database. i use editor text alignment and formating. after i retrive the data in listview using label control . i got following output
,<strong> which includes performances by hundreds</strong> of artists. <p> The city has a vibrant theatre scene and is an important centre for the Bharata Natyam, a classical Chennai is an important centre for Carnatic music and hosts a large cultural
event, the annual Madras Music Seaso<span style="color: #00b050;">n, which includ</span>es performances by hundreds of artists. The city has a vibrant theatre scene and is an important centre for the Bharata Natyam, a classical dance form. The Tamil film industry,
the second largest film industry i<span style="background-color: #ff0000;">n India, is based in Chennai. </span></p>
SudhaRubini
Member
391 Points
383 Posts
Html text to n ormal text in text editor
Apr 18, 2012 04:34 AM|LINK
Hi
i have an text editor. save the data to database. i use editor text alignment and formating. after i retrive the data in listview using label control . i got following output
,<strong> which includes performances by hundreds</strong> of artists. <p> The city has a vibrant theatre scene and is an important centre for the Bharata Natyam, a classical Chennai is an important centre for Carnatic music and hosts a large cultural event, the annual Madras Music Seaso<span style="color: #00b050;">n, which includ</span>es performances by hundreds of artists. The city has a vibrant theatre scene and is an important centre for the Bharata Natyam, a classical dance form. The Tamil film industry, the second largest film industry i<span style="background-color: #ff0000;">n India, is based in Chennai. </span></p>
my code is
<dnn:texteditor id="txtContent" runat="server" height="200" width="500" />
and binding is
<asp:Label ID="lblCoursenews" runat="server" Text='<%# Eval("FirstContent") %>' Title='<%# Eval("FirstContent") %>' ForeColor="Green" Font-Bold="true"></asp:Label>
please help me how can get html text to normal text.
if i change text formating mean it ll apply and then retrive for normal text. can you help me.......
nijhawan.sau...
All-Star
16400 Points
3173 Posts
Re: Html text to n ormal text in text editor
Apr 18, 2012 04:47 AM|LINK
Label control would itself show Normal text, even if it's Text property is some html content.
Just check if your html text is proper or not, i mean all starting tags have ending tags etc.
cninjas
Contributor
4868 Points
851 Posts
Re: Html text to n ormal text in text editor
Apr 18, 2012 05:00 AM|LINK
hi
are else you just try to write Response.Write the html content and check it out.
can u try it?
Niranjan
SudhaRubini
Member
391 Points
383 Posts
Re: Html text to n ormal text in text editor
Apr 18, 2012 05:02 AM|LINK
hi
i want to view in normal text. while iam saving it ll save html. when i ll view the text i want o view normal text. what i do?
how can i convert normal text.
cninjas
Contributor
4868 Points
851 Posts
Re: Html text to n ormal text in text editor
Apr 18, 2012 09:16 AM|LINK
hi
I think you want to remove the HTML tags and display it as plain text.
this is my sample showing the same
<asp:DataList ID="DataList1" runat="server"> <ItemTemplate> <asp:Label ID="lblCoursenews" runat="server" Text='<%# strConvert(DataBinder.Eval(Container.DataItem, "h").ToString())%>' ForeColor="Green" Font-Bold="true"></asp:Label> </ItemTemplate> </asp:DataList>And then in your code behind copy the class file for conversion
/// <summary> /// Methods to remove HTML from strings. /// </summary> public static class HtmlRemoval { /// <summary> /// Remove HTML from string with Regex. /// </summary> public static string StripTagsRegex(string source) { return Regex.Replace(source, "<.*?>", string.Empty); } /// <summary> /// Compiled regular expression for performance. /// </summary> static Regex _htmlRegex = new Regex("<.*?>", RegexOptions.Compiled); /// <summary> /// Remove HTML from string with compiled Regex. /// </summary> public static string StripTagsRegexCompiled(string source) { return _htmlRegex.Replace(source, string.Empty); } /// <summary> /// Remove HTML tags from string using char array. /// </summary> public static string StripTagsCharArray(string source) { char[] array = new char[source.Length]; int arrayIndex = 0; bool inside = false; for (int i = 0; i < source.Length; i++) { char let = source[i]; if (let == '<') { inside = true; continue; } if (let == '>') { inside = false; continue; } if (!inside) { array[arrayIndex] = let; arrayIndex++; } } return new string(array, 0, arrayIndex); } }and then in your page code behind do this to get rid of html tags while displaying.
/// <summary> /// Remove HTML from string with compiled Regex. /// </summary> public static string StripTagsRegexCompiled(string source) { return _htmlRegex.Replace(source, string.Empty); }Hope it helps.thanks.
Niranjan