dear you must be hitting "Enter" button at the end of each line. If so, then let me tell you my users are not going to hit "Enter" at the end of each line. i need output without it.
The code suggested in above posts and the recent one from you are correct.
But this is not going to help if you dont hit enter while inserting into multiline textbox between lines.
try doing that....:-)
Good point me_ritz. Of course it's not going to work if you don't hit enter because then there will be no "\r\n" to replace with "<br/>". You should have someway that the code can identify
the newline in the string.
dear you must be hitting "Enter" button at the end of each line. If so, then let me tell you my users are not going to hit "Enter" at the end of each line. i need output without it.
Well, You can do it hard way then. Remove the width property and use the Columns property to define the width of your textbox. If you are going remove the scrolling of the textarea, you will need to deduct 2 from the value you actually wanted for the width.
For example, if you need 10 characters to be appear, then give Columns=8 because it will add 2 more if you disable the scroll bar(It takes that space, which you get by disabling the textbox, into the textbox). I suggest you to disable the resizing option for
the textbox because if the user resize the textbox, then there is no way that you can get on which point the line breaks. To disable the resizing, you can use the below style
love53906
Member
72 Points
50 Posts
Re: Problem with multiline textbox
Feb 21, 2012 09:06 AM|LINK
dear you must be hitting "Enter" button at the end of each line. If so, then let me tell you my users are not going to hit "Enter" at the end of each line. i need output without it.
Ruchira
All-Star
43044 Points
7034 Posts
MVP
Re: Problem with multiline textbox
Feb 21, 2012 09:06 AM|LINK
Good point me_ritz. Of course it's not going to work if you don't hit enter because then there will be no "\r\n" to replace with "<br/>". You should have someway that the code can identify the newline in the string.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.abhinav1503
Member
70 Points
37 Posts
Re: Problem with multiline textbox
Feb 21, 2012 09:12 AM|LINK
When I try to do this, I am not able to replace "\n", "\r", "\n\r", or "\n\r" with "<br />".
Is anyone else also facing this problem apart from the problems above?
Abhinav Sharma
~*~Please mark the Reply as Answer if this solves your problem. It helps others.~*~
Ruchira
All-Star
43044 Points
7034 Posts
MVP
Re: Problem with multiline textbox
Feb 21, 2012 09:34 AM|LINK
Well, You can do it hard way then. Remove the width property and use the Columns property to define the width of your textbox. If you are going remove the scrolling of the textarea, you will need to deduct 2 from the value you actually wanted for the width. For example, if you need 10 characters to be appear, then give Columns=8 because it will add 2 more if you disable the scroll bar(It takes that space, which you get by disabling the textbox, into the textbox). I suggest you to disable the resizing option for the textbox because if the user resize the textbox, then there is no way that you can get on which point the line breaks. To disable the resizing, you can use the below style
.resize { resize:none; }So my sample application looks like below.
Note: I have remove the Width attribute and changed the Columns to 8. But it will take 10 characters.
In code behind
protected void btnAdd_Click(object sender, EventArgs e) { string s = txtTextBox1.Text; int initialLength = s.Length; int brLength = 0; for (int i = 1; i < initialLength; i++) { if (i % 10 == 0) { s = s.Insert(i + brLength, "<br/>"); brLength = brLength + 5; } } Label1.Text = s; }btnAdd_Click is your button click event.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.vikramchowda...
Member
484 Points
216 Posts
Re: Problem with multiline textbox
Feb 21, 2012 09:47 AM|LINK
Hi,
Set the proper width to ypur label by that you can get the line below
<asp:Label ID="Label1" runat="server" Text="Label" Width="200px"></asp:Label>
Sincerely,
Vikram
vivekreddy
Member
200 Points
96 Posts
Re: Problem with multiline textbox
Feb 21, 2012 09:51 AM|LINK
your code is working fine love..try to execute in different browser..