Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Working interchangeably with vbCrLf in a TextBox and <br> in a Label

Reply
Thread Tools

Working interchangeably with vbCrLf in a TextBox and <br> in a Label

 
 
Jim in Arizona
Guest
Posts: n/a
 
      06-12-2008
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


 
Reply With Quote
 
 
 
 
Jim in Arizona
Guest
Posts: n/a
 
      06-13-2008

"Jim in Arizona" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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>") %>' />


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dll config and web.config and Label Expressions (binding label text to dll config settings) CSharpner ASP .Net 0 04-09-2007 09:00 PM
Re: Simple question about 'vbCrLf' is not declared GrantMagic ASP .Net 0 09-21-2004 04:32 PM
Re: Simple question about 'vbCrLf' is not declared Hermit Dave ASP .Net 0 09-21-2004 04:30 PM
How to combine the LEFT and VbCrLF thingy with a single text fiiled ... Evertjan. ASP General 2 11-23-2003 08:15 PM
How to combine both LEFT and VbCrLf thingy to a single field while displaying techy techno Javascript 1 11-23-2003 09:35 AM



Advertisments