The subject of the post is rather long but I didn't know how to put it in a shorter way [:D]
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.
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("description").
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 a textbox but this gives a scrollbar and this I don't want.
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
aspsksolutions.com there is also a link to FreeTextBox.
Thanks for the info. I already stumbled on your website when searching through the forum messages.
I was just wondering if there would be a standard ASP.NET solution built-in, but apparently not.
One issue I have with this FTB is that I have to include
<pages
validateRequest="false" />
in the Web.config file. Somewhere I read something that the Server.HtmlEncode function can solve this issue.
Now my question is, is it possible to include it in the ASP control? What I mean is can you use like eg.
Text='<%# Server.HtmlEncode(Bind("description")) %>'
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
Protected
Sub OnSave or something similar?
I had to do just this in the forums code I made. If you just want to stay with the regular textbox then...
This is for News_Edit.aspx (changing Event_Edit.aspx or Location_Edit would be very similar)
Add these 2 event handlers to encode the text and format it when it is posted/updated:
' Encode the inserted description so it displays properly in the html page
Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs)
' encode the text to prevent XSS hacking
Dim desc As String = HttpUtility.HtmlEncode(e.Values.Item("description").ToString())
' turn line breaks into BR tags
desc = Regex.Replace(desc, "\r\n", "<br />", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
' turn any BR tags that were encoded back into BR tags
desc = Regex.Replace(desc, "<br />", "<br />", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
e.Values.Item("description") = desc
End Sub
' Encode the updated description so it displays properly in the html page
Protected Sub FormView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewUpdateEventArgs)
' encode the text to prevent XSS hacking
Dim desc As String = HttpUtility.HtmlEncode(e.NewValues.Item("description").ToString())
' turn line breaks into BR tags
desc = Regex.Replace(desc, "\r\n", "<br />", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
' turn any BR tags that were encoded back into BR tags
desc = Regex.Replace(desc, "<br />", "<br />", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
e.NewValues.Item("description") = desc
End Sub
Then change this event so that when text is displayed for editing, it is decoded and unformatted:
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
If FormView1.CurrentMode = FormViewMode.Insert Then
CType(FormView1.FindControl("dtpicker"), DateandTimePicker).selectedDateTime = Now
Else
Dim cb As CheckBox = CType(FormView1.FindControl("CheckBox1"), CheckBox)
Dim surl As TextBox = CType(FormView1.FindControl("staticURLTextBox"), TextBox)
If surl.Text <> "" Then
cb.Checked = True
surl.Enabled = True
Else
surl.Enabled = False
End If
End If
' Decode the description text for editing
If FormView1.CurrentMode = FormViewMode.Edit Then
' get the textbox
Dim descBox As TextBox = CType(FormView1.FindControl("descriptionTextBox"), TextBox)
' decode the text from it
Dim decodedText As String = HttpUtility.HtmlDecode(descBox.Text)
' turn BR tgas into line feeds
decodedText = Regex.Replace(decodedText, "<br />", vbCrLf)
' put the decoded text back in the box
descBox.Text = decodedText
End If
End Sub
Limmer
Member
40 Points
11 Posts
Show Event and Announcement descriptions as entered in the database
May 08, 2006 09:34 PM|LINK
Hi all,
The subject of the post is rather long but I didn't know how to put it in a shorter way [:D]
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.
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("description").
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 a textbox but this gives a scrollbar and this I don't want.
Thanks for any help/tips to get this one solved,
Limmer
MaineOne
Contributor
2087 Points
469 Posts
Re: Show Event and Announcement descriptions as entered in the database
May 08, 2006 10:46 PM|LINK
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 aspsksolutions.com there is also a link to FreeTextBox.
Limmer
Member
40 Points
11 Posts
Re: Show Event and Announcement descriptions as entered in the database
May 10, 2006 06:36 PM|LINK
Thanks for the info. I already stumbled on your website when searching through the forum messages.
I was just wondering if there would be a standard ASP.NET solution built-in, but apparently not.
One issue I have with this FTB is that I have to include <pages validateRequest="false" /> in the Web.config file. Somewhere I read something that the Server.HtmlEncode function can solve this issue.
Now my question is, is it possible to include it in the ASP control? What I mean is can you use like eg. Text='<%# Server.HtmlEncode(Bind("description")) %>'
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 Protected Sub OnSave or something similar?
Limmer
MrLunch
Member
727 Points
144 Posts
Re: Show Event and Announcement descriptions as entered in the database
May 10, 2006 07:12 PM|LINK
I had to do just this in the forums code I made. If you just want to stay with the regular textbox then...
This is for News_Edit.aspx (changing Event_Edit.aspx or Location_Edit would be very similar)
Add these 2 event handlers to encode the text and format it when it is posted/updated:
' Encode the inserted description so it displays properly in the html page
Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs)
' encode the text to prevent XSS hacking
Dim desc As String = HttpUtility.HtmlEncode(e.Values.Item("description").ToString())
' turn line breaks into BR tags
desc = Regex.Replace(desc, "\r\n", "<br />", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
' turn any BR tags that were encoded back into BR tags
desc = Regex.Replace(desc, "<br />", "<br />", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
e.Values.Item("description") = desc
End Sub
' Encode the updated description so it displays properly in the html page
Protected Sub FormView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewUpdateEventArgs)
' encode the text to prevent XSS hacking
Dim desc As String = HttpUtility.HtmlEncode(e.NewValues.Item("description").ToString())
' turn line breaks into BR tags
desc = Regex.Replace(desc, "\r\n", "<br />", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
' turn any BR tags that were encoded back into BR tags
desc = Regex.Replace(desc, "<br />", "<br />", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
e.NewValues.Item("description") = desc
End Sub
Then change this event so that when text is displayed for editing, it is decoded and unformatted:
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
If FormView1.CurrentMode = FormViewMode.Insert Then
CType(FormView1.FindControl("dtpicker"), DateandTimePicker).selectedDateTime = Now
Else
Dim cb As CheckBox = CType(FormView1.FindControl("CheckBox1"), CheckBox)
Dim surl As TextBox = CType(FormView1.FindControl("staticURLTextBox"), TextBox)
If surl.Text <> "" Then
cb.Checked = True
surl.Enabled = True
Else
surl.Enabled = False
End If
End If
' Decode the description text for editing
If FormView1.CurrentMode = FormViewMode.Edit Then
' get the textbox
Dim descBox As TextBox = CType(FormView1.FindControl("descriptionTextBox"), TextBox)
' decode the text from it
Dim decodedText As String = HttpUtility.HtmlDecode(descBox.Text)
' turn BR tgas into line feeds
decodedText = Regex.Replace(decodedText, "<br />", vbCrLf)
' put the decoded text back in the box
descBox.Text = decodedText
End If
End Sub
Forums Starter Kit
Limmer
Member
40 Points
11 Posts
Re: Show Event and Announcement descriptions as entered in the database
May 10, 2006 07:55 PM|LINK
Hi Mark,
Thanks for your reaction, that's exactly what I needed for now.
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.
Thanks to both for the reactions [:D][:D]
Limmer