Multiline TextBox multiple newline

前端 未结 7 486
Happy的楠姐
Happy的楠姐 2020-12-05 10:09

I set a value for a Multiline Textbox like this.

textBox1.Text = \"Line1\\r\\n\\r\\nLine2\";

But, only one line space in outpu

相关标签:
7条回答
  • 2020-12-05 10:44

    I had the same problem. If I add one Environment.Newline I get one new line in the textbox. But if I add two Environment.Newline I get one new line. In my web app I use a whitespace modul that removes all unnecessary white spaces. If i disable this module I get two new lines in my textbox. Hope that helps.

    0 讨论(0)
  • 2020-12-05 10:45

    textBox1.Text = "Line1\r\r\Line2";
    Solved the problem.

    0 讨论(0)
  • 2020-12-05 10:48
    textBox1.Text = "Line1" + Environment.NewLine + "Line2";
    

    Also the markup needs to include TextMode="MultiLine" (otherwise it shows text as one line)

    <asp:TextBox ID="multitxt" runat="server" TextMode="MultiLine" ></asp:TextBox>
    
    0 讨论(0)
  • 2020-12-05 10:51

    When page IsPostback, the following code work correctly. But when page first loading, there is not multiple newline in the textarea. Bug

    textBox1.Text = "Line1\r\n\r\n\r\nLine2";
    
    0 讨论(0)
  • 2020-12-05 10:55

    Try this one

    textBox1.Text = "Line1" + Environment.NewLine + "Line2";

    Working fine for me...

    0 讨论(0)
  • 2020-12-05 10:57

    You need to set the textbox to be multiline, this can be done two ways:

    In the control:

    <asp:TextBox runat="server" ID="MyBox" TextMode="MultiLine" Rows="10" />
    

    Code Behind:

    MyBox.TextMode = TextBoxMode.MultiLine;
    MyBox.Rows = 10;
    

    This will render as a <textarea>

    0 讨论(0)
提交回复
热议问题