Solved

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

Posted on 2014-09-03
5
267 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
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 74

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 74

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now