Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

786 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