murday1983
murday1983

Reputation: 4026

Multi Line Text Box Displays HTML Elements When Going Back To Page

I have an asp.net web form which on one page has a multi line textbox. When the user types in this field and continues the details are displayed on a confirmation page and displays as the user entered

Example

This is the first line

This is the second line

But when I click my edit button (which directs me back to my page) my textbox displays as

This is the first line<br /><br />This is the second line

I want it to keep its styling but don't know how to do this. The details are stored in the session.

Code behind

protected void Step07SubmitButton_Click(object sender, EventArgs e)
{
    Session["Step07OtherDetailsField"] = Step07OtherDetailsField.Text.Replace("\r\n", "<br />");
    Response.Redirect("/Quotation/pg3.aspx");
}

I tried the following in my Page_Load

Step07OtherDetailsField.Text.Replace("<br />", "\r\n");

and also

Step07OtherDetailsField.Text.Replace("<br />", Environment.NewLine);

But for some reason when I debug it, it says that my .text is empty but the previous wording is actually still displayed in the field and the <br /> is also still displayed.

Upvotes: 0

Views: 386

Answers (1)

Vimal Vataliya
Vimal Vataliya

Reputation: 61

You don't need to replace anything. You just store value in session and display it to any textbox, it will maintain \r and \t.

If you want to display result in span then display result to textbox with multiline then apply css for no border,etc.

Upvotes: 1

Related Questions