Show Event and Announcement descriptions as entered in the databasehttp://forums.asp.net/t/988802.aspx/1?Show+Event+and+Announcement+descriptions+as+entered+in+the+databaseWed, 10 May 2006 19:55:02 -04009888021279807http://forums.asp.net/p/988802/1279807.aspx/1?Show+Event+and+Announcement+descriptions+as+entered+in+the+databaseShow Event and Announcement descriptions as entered in the database <p><font face="Arial" size="2">Hi all,</font></p> <p><font face="Arial" size="2">The subject of the post is rather long but I didn't know how to put it in a shorter way [:D]</font></p> <p><font face="Arial" size="2">What my problem is, is the following. For the Events and News a description can be entered. When I put some returns in the description via the textbox, it puts it in that form in the database, but when you view this info via Events_view or News_view then these returns lines are not there anymore and everything is displayed in one continues line.</font></p> <p><font face="Arial" size="2">I know it's not a database storing problem as it is correct there, so it must be the Label control that does this. It is possible to put returns in a Label control, but apparently this is not working when doing this via Eval(&quot;description&quot;).</font></p> <p><font face="Arial" size="2">Is there an other way of getting the view to show how it is entered in the database? I've been looking into displaying the data via&nbsp;a textbox but this gives a scrollbar and this I don't want.</font></p> <p><font face="Arial" size="2">Thanks for any help/tips to get this one solved,</font></p> <p><font face="Arial" size="2">Limmer</font></p> 2006-05-08T21:34:25-04:001279869http://forums.asp.net/p/988802/1279869.aspx/1?Re+Show+Event+and+Announcement+descriptions+as+entered+in+the+databaseRe: Show Event and Announcement descriptions as entered in the database <p>One solution is to switch to FreeTextBox, it allows for greater editing of news content and it will show it formatted corectly in News View. you can see an example on my site <a href="http://aspsksolutions.com">aspsksolutions.com</a>&nbsp;there is also a link to FreeTextBox.</p> <p>&nbsp;</p> 2006-05-08T22:46:22-04:001282151http://forums.asp.net/p/988802/1282151.aspx/1?Re+Show+Event+and+Announcement+descriptions+as+entered+in+the+databaseRe: Show Event and Announcement descriptions as entered in the database <p><font face="Arial" size="2">Thanks for the info. I already stumbled on your website when searching through the forum messages.<br> I was just wondering if there would be a standard ASP.NET solution built-in, but apparently not.<br> <br> One issue I have with this FTB is that I have to include <font color="#0000ff" size="2"> &lt;</font><font color="#800000" size="2">pages</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">validateRequest</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">false</font><font size="2">&quot;</font><font color="#0000ff" size="2"> /&gt; <font color="#000000">in the Web.config file. Somewhere I read something&nbsp;that&nbsp;the Server.HtmlEncode function can solve this issue.<br> Now my question is, is it possible to include it in the ASP control? What I mean is can you use like eg. <font color="#ff0000" size="2">Text</font><font color="#0000ff" size="2">='</font><font size="2">&lt;%# Server.HtmlEncode(Bind(&quot;description&quot;)) %&gt;</font><font color="#0000ff" size="2">'</font></font></font></font></p> <p><font face="Arial" size="2"><font color="#0000ff" size="2"><font color="#000000"><font color="#0000ff" size="2"><font color="#000000">I know the line above is not working, but is there a way to implement in that way or will I have to do this in some</font> <font color="#0000ff" size="2">Protected</font><font color="#000000" size="2"> </font> <font color="#0000ff" size="2">Sub OnSave <font color="#000000">or something similar?</font></font></font></font></font></font></p> <p><font face="Arial" size="2"><font color="#0000ff" size="2"><font color="#000000"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#000000">Limmer</font></p> </font></font></font></font></font> 2006-05-10T18:36:15-04:001282195http://forums.asp.net/p/988802/1282195.aspx/1?Re+Show+Event+and+Announcement+descriptions+as+entered+in+the+databaseRe: Show Event and Announcement descriptions as entered in the database <p>I had to do just this in the forums code I made. If you just want to stay with the regular textbox then...</p> <p>This is for News_Edit.aspx (changing Event_Edit.aspx or Location_Edit would be very similar)</p> <p>Add these 2 event handlers to encode the text and format it when it is posted/updated:</p> <p><font face="Courier New" size="2">&nbsp;&nbsp;&nbsp; <font color="#006400">' Encode the inserted description so it displays properly in the html page<br> </font>&nbsp;&nbsp;&nbsp; Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#006400">' encode the text to prevent XSS hacking<br> </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim desc As String = HttpUtility.HtmlEncode(e.Values.Item(&quot;description&quot;).ToString())<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#006400">' turn line breaks into BR tags<br> </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; desc = Regex.Replace(desc, &quot;\r\n&quot;, &quot;&lt;br /&gt;&quot;, RegexOptions.IgnoreCase Or RegexOptions.Multiline)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#006400">' turn any BR tags that were encoded back into BR tags<br> </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; desc = Regex.Replace(desc, &quot;&amp;lt;br /&amp;gt;&quot;, &quot;&lt;br /&gt;&quot;, RegexOptions.IgnoreCase Or RegexOptions.Multiline)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.Values.Item(&quot;description&quot;) = desc<br> &nbsp;&nbsp;&nbsp; End Sub</font></p> <p><font face="Courier New" size="2">&nbsp;&nbsp;&nbsp; <font color="#006400">' Encode the updated description so it displays properly in the html page<br> </font>&nbsp;&nbsp;&nbsp; Protected Sub FormView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewUpdateEventArgs)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#006400">' encode the text to prevent XSS hacking</font><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim desc As String = HttpUtility.HtmlEncode(e.NewValues.Item(&quot;description&quot;).ToString())<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#006400">' turn line breaks into BR tags<br> </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; desc = Regex.Replace(desc, &quot;\r\n&quot;, &quot;&lt;br /&gt;&quot;, RegexOptions.IgnoreCase Or RegexOptions.Multiline)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#006400">' turn any BR tags that were encoded back into BR tags<br> </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; desc = Regex.Replace(desc, &quot;&amp;lt;br /&amp;gt;&quot;, &quot;&lt;br /&gt;&quot;, RegexOptions.IgnoreCase Or RegexOptions.Multiline)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.NewValues.Item(&quot;description&quot;) = desc<br> &nbsp;&nbsp;&nbsp; End Sub</font></p> <p>Then change this event so that when text is displayed for editing, it is decoded and unformatted:</p> <p><br> <font face="Courier New" size="2">&nbsp;&nbsp;&nbsp; Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If FormView1.CurrentMode = FormViewMode.Insert Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CType(FormView1.FindControl(&quot;dtpicker&quot;), DateandTimePicker).selectedDateTime = Now<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim cb As CheckBox = CType(FormView1.FindControl(&quot;CheckBox1&quot;), CheckBox)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim surl As TextBox = CType(FormView1.FindControl(&quot;staticURLTextBox&quot;), TextBox)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If surl.Text &lt;&gt; &quot;&quot; Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cb.Checked = True<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; surl.Enabled = True<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; surl.Enabled = False<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#006400">' Decode the description text for editing<br> </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If FormView1.CurrentMode = FormViewMode.Edit Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#006400">' get the textbox<br> </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim descBox As TextBox = CType(FormView1.FindControl(&quot;descriptionTextBox&quot;), TextBox)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#006400">' decode the text from it<br> </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim decodedText As String = HttpUtility.HtmlDecode(descBox.Text)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#006400">' turn BR tgas into line feeds<br> </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; decodedText = Regex.Replace(decodedText, &quot;&lt;br /&gt;&quot;, vbCrLf)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#006400">' put the decoded text back in the box<br> </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; descBox.Text = decodedText<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> &nbsp;&nbsp;&nbsp; End Sub</font></p> <p><font face="Courier New" size="1"></font>&nbsp;</p> 2006-05-10T19:12:47-04:001282260http://forums.asp.net/p/988802/1282260.aspx/1?Re+Show+Event+and+Announcement+descriptions+as+entered+in+the+databaseRe: Show Event and Announcement descriptions as entered in the database <p><font face="Arial">Hi Mark,</font></p> <p><font face="Arial">Thanks for your reaction, that's exactly what I needed for now.<br> <br> Perhaps I will start using that FreeTextBox control in the future as it is also working very fine and adds a lot of extra text editing possibilities.<br> <br> Thanks to both&nbsp;for the reactions [:D][:D]</font></p> <p><font face="Arial">Limmer</font></p> 2006-05-10T19:55:02-04:00