Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying a text & linebreaks in a textfield

Status
Not open for further replies.

gregburningham

Programmer
Jul 12, 2000
40
0
0
GB
Hi

I am trying to write some text out to a textfield on an asp.net page.

I would like the text to be displayed in one textfields as follows:

- Message 1
- Message 2
- Message 3

Each string of text should be separated with some sort of line break character I assume. (I will build the string programatically). I have tried using chr(10) and VbCrLf but neither seem to work and the text is appearing as follows:

-Message 1Message 2Message3

Please can someone help me ?

Thanks in Advance ...
Greg B
 
What is your code to create the string of text?
 
Public Class WebForm2
Inherits System.Web.UI.Page
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox4 As System.Web.UI.WebControls.TextBox
Protected WithEvents lblValidate1 As System.Web.UI.WebControls.Label
Protected WithEvents lblValidate2 As System.Web.UI.WebControls.Label
Protected WithEvents lblSummaryValidate As System.Web.UI.WebControls.Label
Protected WithEvents TextBox3 As System.Web.UI.WebControls.TextBox
Protected WithEvents Repeater1 As System.Web.UI.WebControls.Repeater
Protected WithEvents Label1 As System.Web.UI.WebControls.Label


#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Experimental Code
'Put user code to initialize the page here
lblValidate1.Visible = False
lblValidate2.Visible = False

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

lblSummaryValidate.Text = &quot;&quot;
lblValidate1.Visible = False
lblValidate2.Visible = False

TextBox4.Text = &quot;4&quot;

If TextBox4.Text = &quot;4&quot; Then
If TextBox1.Text = &quot;&quot; Then
lblValidate1.Visible = True
TextBox3.Text = &quot;TextBox1 cannot be empty&quot;
End If

If TextBox2.Text = &quot;&quot; Then
TextBox2.Visible = True
lblValidate2.Visible = True
TextBox3.Text = TextBox3.Text & Chr(10) & &quot;TextBox2 cannot be empty&quot;
End If
End If

End Sub
End Class
 
Is the multiline property on your textbox set to True?

 
If I set it to true I get an unwanted scrollbar ...(Is there any way of removing this?)

Even then the text does not appear as desired ...?


Thanks
Greg B

 
Think the scroll bar stays. The way you have your code, it will keep adding lines to the text box.

Do you want this or just display 2 lines at the most if the text boxes aren't filled?

 
Eventually with the addition of more textboxes there may be upto 5 or 6 lines displayed .....

Message 1
Message 2
Message 3
Message 4
Message 5
Message 6

 
yeh, but the way you have it is

click once with empty boxes

Message1
Message2

click again with 1 empty box

Message1
Message2
Message1

You keep adding to the textbox, so if after 20 clicks with some textboxes empty, you may have a long list to show in the textbox.

If you only want to display the current status of your click, eg, only show what textboxes are empty, you should create a string variable in the event and add your message to the string if a textbox is empty. Then at the end, make textbo3.text = Your String
 
I understand what your saying - In fact, the way to get around this scenario is simply to set Textbox3.text = &quot;&quot; at the beginning of the click event ....

The problem is still that I can't display text in a list fashion as in:

Message 1
Message 2
Message 3 etc,

(because line break characters are not being recognised)
Any ideas ?

 
lblSummaryValidate.Text = &quot;&quot;
lblValidate1.Visible = False
lblValidate2.Visible = False

TextBox4.Text = &quot;4&quot;

If TextBox4.Text = &quot;4&quot; Then
If TextBox1.Text = &quot;&quot; Then
lblValidate1.Visible = True
TextBox3.Text = &quot;TextBox1 cannot be empty&quot;
End If

If TextBox2.Text = &quot;&quot; Then
TextBox2.Visible = True
lblValidate2.Visible = True
TextBox3.Text = TextBox3.Text & vbCrLf & &quot;TextBox2 cannot be empty&quot;
End If
End If

I only made the change with the vbCrLF and have the textbox using Multiline. It works, except you have the scrollbar on the side, which may be a good thing if you end up with a heap of messages.
 
Thanks this works - shame I can't get rid of the scrollbar - I'll look into this !

Thanks again !

Greg B

 
What about using a listbox?? Create a new list item every time you find a text field empty. Since its just being used as a message type control, the user doesn't need to be able to edit the text.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top