Results 1 to 3 of 3

Thread: Asp.net multiline textbox not recognising carriage returns

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,373

    Asp.net multiline textbox not recognising carriage returns

    I have an ASP.NET multiline textbox. I can hit return to create carriage returns on the screen but the text property of the textbox is ignoring the carriage returns and simply concatenating the lines without even a space in between. I am writing this text property to a database and I want to be able to retrieve the text exactly as it was typed with carriage returns included.

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Asp.net multiline textbox not recognising carriage returns

    I have this simple application which works.

    aspx code:
    Code:
      
    <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox>
    c# code.
    Code:
    protected void Button1_Click(object sender, EventArgs e)
            {
                //save valueTextbox with carriage return to database
                string valueTextbox = Regex.Replace(this.TextBox1.Text, @"\r\n", "</br>");
                //save database code blah blah blah....
    
                //retrieve from database
                string valueDB = dr["dummytext"].ToString(); //datarow object
                Response.Write(valueDB);
            }
    It renders the text with breaks to the browser.

    Greg
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,373

    Re: Asp.net multiline textbox not recognising carriage returns

    When I looked both in the Visual Studio designer and in the database, the carriage returns weren't visible. It just appeared as a single concatenated string. Carriage returns used to appear as a square box. However, when I copied and pasted the text into notepad, the text was on separate lines so the carriage returns are there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width