Solved

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

Posted on 2014-09-03
5
276 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:mikesExpertExchange
[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 500 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:mikesExpertExchange
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PowerShell:  Where-Object not working as a filter 2 72
asp.net figure out error 3 26
How to force output to ascii 2 41
Selenium and Xpath 4 35
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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