I have taken asp.net textbox like : <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Columns="10" Rows="4"></asp:TextBox> and i have also taken asp.net label control to show a value of above metioned multiline textbox. My problem is i am typing
4 to 5 lines in a multiline textbox but when it comes to showing those lines into a label control. It shows all 5 lines in one line only which i dont want at all. I have tried replacing environment.newline with <br/>, i have tried replacing /n and /r/n with
<br/> too. But nothing worked at all. I am filling label on the button click event. i m using asp.net with c#.
Post your code behind and instead of saying it's not working, tell us what has exactly happened (Didn't get the expected result? Got an unexpected result? Got the same result? An error? Exception?). I've tested this before I posted the reply and it's working
for me, so I'm confused why it's NOT WORKING for you. Following is my aspx in case if you are interested
i m inserting 4 lines in that multiline textbox. and on the click event of button i am doing as mentioned in above code. Those 4 lines should be shown in 4 seperate lines in that label. But label is showing all those 4 lines in one horizontal line only which
i dont want.
I tested your code in chrome and firefox and it's working fine. I entered four lines in the textbox as you said and I got those four lines in
seperate lines in the label. On what browser you are testing? And are you sure that you don't have any styles apply to the label? If so, please post the styles too. It's weird that the same code is working 100% fine for me.
love53906
Member
72 Points
50 Posts
Problem with multiline textbox
Feb 21, 2012 06:07 AM|LINK
Hello frnds,
I have taken asp.net textbox like : <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Columns="10" Rows="4"></asp:TextBox> and i have also taken asp.net label control to show a value of above metioned multiline textbox. My problem is i am typing 4 to 5 lines in a multiline textbox but when it comes to showing those lines into a label control. It shows all 5 lines in one line only which i dont want at all. I have tried replacing environment.newline with <br/>, i have tried replacing /n and /r/n with <br/> too. But nothing worked at all. I am filling label on the button click event. i m using asp.net with c#.
Thanx in advance!!
Esha Desai
Member
541 Points
364 Posts
Re: Problem with multiline textbox
Feb 21, 2012 06:13 AM|LINK
hi,
Give proper width to your Label Control
Like below..
<asp:Label ID="Label1" runat="server" Text="Label" Width="100"></asp:Label>
It will Work..
Angel.........
Remember to click “Mark as Answer” on the post, if it helps you.
salman beher...
All-Star
30711 Points
5871 Posts
Re: Problem with multiline textbox
Feb 21, 2012 06:16 AM|LINK
Hi Love,
check,same discuess here..http://forums.asp.net/t/1323030.aspx
also nice article....
http://geekswithblogs.net/StealThisCode/archive/2006/03/21/WrapLabels.aspx
Thanks...
Sincerely,
Salman
Ruchira
All-Star
43028 Points
7031 Posts
MVP
Re: Problem with multiline textbox
Feb 21, 2012 07:10 AM|LINK
Hi,
I tested the below simple example for you and it worked for me. :)
string s = txtTextBox1.Text; Label1.Text = s.Replace("\r\n", "<br/>");
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.love53906
Member
72 Points
50 Posts
Re: Problem with multiline textbox
Feb 21, 2012 07:47 AM|LINK
it is not working
love53906
Member
72 Points
50 Posts
Re: Problem with multiline textbox
Feb 21, 2012 07:47 AM|LINK
this is not the solution of my problem.
Ruchira
All-Star
43028 Points
7031 Posts
MVP
Re: Problem with multiline textbox
Feb 21, 2012 08:08 AM|LINK
Post your code behind and instead of saying it's not working, tell us what has exactly happened (Didn't get the expected result? Got an unexpected result? Got the same result? An error? Exception?). I've tested this before I posted the reply and it's working for me, so I'm confused why it's NOT WORKING for you. Following is my aspx in case if you are interested
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.love53906
Member
72 Points
50 Posts
Re: Problem with multiline textbox
Feb 21, 2012 08:46 AM|LINK
my html code :
<form id="form1" runat="server">
<table width="100%">
<tr>
<td width="100%">
<asp:textbox id="txtTextBox1" Width="170px" Runat="server" TextMode="MultiLine"></asp:textbox>
<asp:Button ID="btnAdd" runat="server" Text="Add" onclick="btnAdd_Click" />
</td>
</tr>
<tr>
<td width="100%">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td width="100%">
</td>
</tr>
</table>
</form>
code behind :
protected void btnAdd_Click(object sender, EventArgs e)
{
string s = txtTextBox1.Text;
Label1.Text = s.Replace("\r\n", "<br/>");
}
i m inserting 4 lines in that multiline textbox. and on the click event of button i am doing as mentioned in above code. Those 4 lines should be shown in 4 seperate lines in that label. But label is showing all those 4 lines in one horizontal line only which i dont want.
me_ritz
Star
9337 Points
1447 Posts
Re: Problem with multiline textbox
Feb 21, 2012 09:00 AM|LINK
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....:-)
Ruchira
All-Star
43028 Points
7031 Posts
MVP
Re: Problem with multiline textbox
Feb 21, 2012 09:01 AM|LINK
Hello,
I tested your code in chrome and firefox and it's working fine. I entered four lines in the textbox as you said and I got those four lines in seperate lines in the label. On what browser you are testing? And are you sure that you don't have any styles apply to the label? If so, please post the styles too. It's weird that the same code is working 100% fine for me.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.