?
Solved

Why won't System.Environment.Newline create a newline?

Posted on 2014-09-03
5
Medium Priority
?
288 Views
Last Modified: 2014-09-03
I'm trying to create a line of text with carriage returns in it but my code is ignoring the System.Environment.Newline call for some reason. I've also tried putting: "\r\n" into the string as well but to no avail. What am I doing wrong?

HTML

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <asp:Panel ID="pnlManager" runat="server">
        <div class="divManager">
            <div class="divError">
                <asp:Label ID="lblError" runat="server" />
            </div>

C#

    protected void Submit_Click(object sender, EventArgs e)
    {
        lblError.Text = "";

        if (txtDtOfReq.Text.Trim().Equals(""))
        {
            lblError.Text = lblError.Text + "- Date of Request cannot be blank!" + System.Environment.NewLine;
        }
        if (txtEmpName.Text.Trim().Equals(""))
        {
            lblError.Text = lblError.Text + "- Employee name cannot be blank!" + System.Environment.NewLine;
        }
        if (txtHrDtTrmDt.Text.Trim().Equals(""))
        {
            if (!lblError.Equals(""))
                lblError.Text = lblError.Text + System.Environment.NewLine + "- Hire date cannot be blank!";
        }
        if (txtImmSupName.Text.Trim().Equals(""))
        {
            lblError.Text = lblError.Text + "- Immediate supervisor cannot be blank!" + System.Environment.NewLine;
        }
        if (!pUserBranch.Equals("NAT"))
        {
            if ((ddlDepartment.SelectedIndex.Equals(0)) || (ddlPosJobTitle.SelectedIndex.Equals(0)))
            {
                lblError.Text = lblError.Text + "- Please select a department and corresponding position or \"Other\"!" + System.Environment.NewLine;
            }
            if ((ddlPosJobTitle.SelectedValue.Equals("Other")) && (!ddlDepartment.SelectedValue.Equals("Other")))
            {
                if (txtModelAfterTextBox.Text.Trim().Equals(""))
                    lblError.Text = lblError.Text + "- Please enter a description of position to model after in \"Model After:\" text box!" + System.Environment.NewLine;
            }
        }
        else if (pUserBranch.Equals("NAT"))
        {
            if (txtModelAfterTextBox.Text.Trim().Equals(""))
                lblError.Text = lblError.Text + "- Please enter a description of position to model after in \"Model After:\" text box!" + System.Environment.NewLine;
        }
    }

Open in new window

0
Comment
Question by:Michael Sterling
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 22

Expert Comment

by:p_davis
ID: 40301181
what if is your test data going into? just to narrow it down.
0
 
LVL 1

Accepted Solution

by:
kjsiemek earned 2000 total points
ID: 40301189
Just taking a stab here - but since this is ASP, wouldn't you want "<br/>" instead of "\r\n"?  Just a guess.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40301205
To expand on kjsiemek's comment, HTML collapses multiple whitespaces when rendering a document to the screen. If you examine the source code of the rendered page, you most likely will see the newline that you output. However, due to the aforementioned collapsing, you won't see it rendered on the screen. Use the tag that kjsiemek mentions.
0
 
LVL 1

Author Closing Comment

by:Michael Sterling
ID: 40301250
That was it.I do find it strange that in a previous web application the System.Environment.Newline; worked. Obviously I'm missing a detail with regards to the difference of that project vs. this one. Never the less thank you.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40301277
If your text is inside of a <pre> tag, then that tag will respect the text as it is--meaning that all whitespace and newlines are displayed exactly as they are. Without using a <pre> tag, whitespace will be collapsed.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question