943,074 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 2466
  • C# RSS
Jun 5th, 2009
0

Recognize and use spaces in multiline textbox

Expand Post »
Okay so I have a multiline textbox that accepts user input and stores it in a database. I then have another form that queries for this field and displays it. Everything is working fine, except for the fact that it won't recognize new lines when the user presses enter. I am at a loss.

I need the form to in some way, accept enter to create a new line and output it from the database with the line breaks the way the user inputs them.

This is aspx with sqlserver if it matters.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
thacravedawg is offline Offline
38 posts
since Feb 2009
Jun 5th, 2009
1

Re: Recognize and use spaces in multiline textbox

if this is aspx why didnt you post it there?
you have to replace newline characters with <br /> so it displays properly. i created a sample application, i attach it to this post :

Default.aspx :


C# Syntax (Toggle Plain Text)
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >
  6. <head runat="server">
  7. <title>Untitled Page</title>
  8. </head>
  9. <body>
  10. <form id="form1" runat="server">
  11. <div>
  12. <asp:TextBox ID="TextBox1" runat="server" Height="89px" TextMode="MultiLine"></asp:TextBox>
  13. <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
  14. </form>
  15. </body>
  16. </html>

Default.aspx.cs :

C# Syntax (Toggle Plain Text)
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10.  
  11. public partial class _Default : System.Web.UI.Page
  12. {
  13. protected void Page_Load(object sender, EventArgs e)
  14. {
  15.  
  16. }
  17. protected void Button1_Click(object sender, EventArgs e)
  18. {
  19. Response.Write( TextBox1.Text.Replace(Environment.NewLine, "<br />"));
  20. }
  21. }
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008
Jun 5th, 2009
0

Re: Recognize and use spaces in multiline textbox

i couldnt attach the project to the previous post so here it is
Attached Files
File Type: zip WebSite1.zip (996 Bytes, 39 views)
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Class Interface
Next Thread in C# Forum Timeline: Decompress large file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC