For Programmers: Free Programming Magazines  


Home > Archive > ASP .NET > June 2008 > Re: Working interchangeably with vbCrLf in a TextBox and <br> in a Label [RESOL









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Working interchangeably with vbCrLf in a TextBox and <br> in a Label [RESOL
Jim in Arizona

2008-06-13, 7:35 pm


"Jim in Arizona" <tiltowait@hotmail.com> wrote in message
news:OF7v99NzIHA.3920@TK2MSFTNGP02.phx.gbl...
> On one page I have a datalist where a message is bound to a label.
> On another page I have the datalist which allows for the insert of new
> message as well as being able to edit those messages. The editing
> (EditItemTemplate) has a textbox that loads the message into its text
> property.
> The problem I'm running into is working with vbCrLf and <br>
> interchangeably between the textbox on the admin page and the label on the
> general message page. I want line breaks to be visible in the label but I
> also want these visible in the textbox.
>
> In the EditItemTemplate, I can do something like this when they save the
> edited message:
>
> Dim txtMngrMessageEdit As New TextBox
> txtMngrMessageEdit = e.Item.FindControl("txtMngrMessageEdit")
> txtMngrMessageEdit.Text = Replace(txtMngrMessageEdit.Text, vbCrLf, "<br>")
>
> This way, when the label on the message page displays the message, the
> line breaks are produced correctly. However, if the manager goes to edit
> the message again, the message now shows <br> within the message and all
> the text on a single line within the textbox.
>
> I was thinking about doing the reverse when they click the Edit button:
>
> Dim txtMngrMessageEdit As New TextBox
> txtMngrMessageEdit = e.Item.FindControl("txtMngrMessageEdit")
> txtMngrMessageEdit.Text = Replace(txtMngrMessageEdit.Text, "<br>", vbCrLf)
>
> This returns an Error "Object reference not set to an instance of an
> object" within a pop up box.
>
> I could replace the Label control with a textbox control on the message
> page but then I wouldn't be able to show longer messages in their entirety
> like I could with a label control that adjusts its height according to the
> size of the message. If I replace the label with a textbox and set a
> static height on the text box with textmode="multiline", it would look
> unprofessional (for this application) and take up more page space
> (vertically) than is necessary.
>
> What's the best way to work around this? Is there a way to set a textbox's
> height to the vertical size of the lines of text within it? If I could do
> that, then my problem would be solved. Or, if there's a way to fix the
> Label control to properly display vbCrLf so I don't have to manually force
> in <br> tags from a textbox control.
>
> TIA,
> Jim
>


My thanks to Aaron Bertrand, SQL Server MVP, for assisting me with finding
an answer to my problem from the microsoft.public.sqlserver.programming
group.

I was able to resolve this issue by using the Replace function within the
Text property of the Label itself.

<asp:Label ID="lblManagerMsg" runat="server" Font-Names="Tahoma"
Text='<%#REPLACE(Eval("message"),vbCrLf,"<br>") %>' />


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com