Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 15th, 2009, 07:56 AM
Authorized User
 
Join Date: Jul 2009
Posts: 61
Thanks: 15
Thanked 1 Time in 1 Post
Default Enabling users to update webpage text content

Hi,
I want to give my users the ability to update certain aeas of their web pages themselves.

I present each area using a formview which displays just one field from a database table which contains a row for each page and fields for each text area.

My issue is that when text is typed into the textbox to update the field (and therefor the web page) carriage returns are ignored. i.e. this message would come out as a single block of text with no paragraphs

Is there a way to achieve what I want with a single field, or have I got to specify a field for each paragraph of text I want to provide them with?


Also, In the page that does the database updating I have the code:
Code:
Partial Class Management_AddEditEvents
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Request.QueryString.Get("Id") IsNot Nothing Then
            DetailsView1.DefaultMode = DetailsViewMode.Edit
        End If
    End Sub
    Private Sub EndEditing()
        Response.Redirect("Events.aspx")
    End Sub
End Class
I expected the sub Enditing () to take me back to the Events.aspx page after the update has been carried out (as per page Chap 12 p422) but it doesn't :(
__________________
Geoff Baldwin
 
Old July 15th, 2009, 09:52 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

In order for the line breaks to work, you need to replace them with HTML <br /> tags, like this

Dim output As String = Whatever You need to do to assign the string with breaks here
output = output.Replace(ControlChars.NewLine, "<br />")

With regards to EndEditing: it does exactly what you think. However, in order for the Sub to work you need to call it somewhere. Don't know where you need it, but calling it like this:

EndEditing()

Should do the trick.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old July 15th, 2009, 01:42 PM
Authorized User
 
Join Date: Jul 2009
Posts: 61
Thanks: 15
Thanked 1 Time in 1 Post
Default

Thanks Imar,
using your response and info from p419 of the book I was able to inset the <BR /> commands in the text before it was stored in the database and it displays perfectly in the website.
The downside is that the user then sees the <br /> commands in the text box he is updating.

For a better look and feel I experimented with replacing the linebreak controls with the <br /> when loading the formview so that it displays correctly but the <br /> are not held in the database.
ie by putting similar code in a
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound or Databinding Sub

Unfortunatley, I cannot figurre out how to reference the field in the Formview Itemtemplate in the same way as I did when editing it where I used e.newvalues("LeftColumn") successfully.
As I am only displayiong data via the control I only have an <ItemTemplate>
__________________
Geoff Baldwin
 
Old July 15th, 2009, 01:55 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Geoff,

Your solution is, IMH, the better one and was actually what I had in mind. By changing the code when you display it, you keep the database clean from HTML-specific content which makes it easier to reuse that content (for example, in an e-mail).

You can call the Replace function in your template when you're binding. Something like this:

<asp:Label .... Text = '<%# Eval("SomeField").ToString().Replace(ControlChars. NewLine, <br />") ' ... />

This calls ToString on the field to convert it to a string. The Replace is called on the result which eventually results in a properly displayed value.

You may need to convert your fields / columns to templates first in order to get to conrols like a Label.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
SouthendSupporter (July 15th, 2009)
 
Old July 15th, 2009, 06:36 PM
Authorized User
 
Join Date: Jul 2009
Posts: 61
Thanks: 15
Thanked 1 Time in 1 Post
Default

Imar -- REALLY useful, works a treat!
Many thanks.
__________________
Geoff Baldwin
 
Old July 16th, 2009, 03:41 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're welcome....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Snag webpage content marshall04b Perl 1 November 20th, 2008 01:06 PM
Insert text into webpage textbox vutaviva C# 1 November 26th, 2006 08:16 PM
HELP with text boxes on webpage rwheeleragco Javascript How-To 1 November 2nd, 2004 04:32 AM
Using VBScript to update content w/o page refresh ALoPresto Classic ASP Basics 2 July 11th, 2003 12:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.