This is a migrated thread and some comments may be shown as answers.

Maintaining linebreaks in multiline RadTextBox

5 Answers 544 Views
Input
This is a migrated thread and some comments may be shown as answers.
Alan T
Top achievements
Rank 1
Alan T asked on 19 Aug 2011, 10:05 AM
Pretty simple question. I'm sure its quite easy but its causing me some trouble.

I've written these 2 lines, neither or which seem to pick up on the line breaks.

desc = Replace(Me.txt_description.Text, System.Environment.NewLine, "<br />")
 
desc = Replace(Me.txt_description.Text, vbCr, "<br />")

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Aug 2011, 10:46 AM
Hello Alan,

Try the following code snippet.
protected void Page_Load(object sender, EventArgs e)
   {
       radtxtbox.Text = radtxtbox.Text + "FirstLine\n";
       radtxtbox.Text = radtxtbox.Text + "SecondLine";
   }

Thanks,
Shinu.
0
Alan T
Top achievements
Rank 1
answered on 19 Aug 2011, 10:52 AM
post may have been a bit misleading. i actually want to transform the linebreaks into html line breaks (<br />) tags, so when i pull the data out of hte database for displaying in a html control the line breaks will show. 

Should my replace function be looking for the string "\n" in the text box instead?
0
Alan T
Top achievements
Rank 1
answered on 23 Aug 2011, 12:26 PM
Ok this is proving to be more difficult than it should be.

So i enter some data into a mutli line text box. I commit it to the database, i use HttpUtility.HtmlEncode
I then decode it when i pull it back out.

If i populate a multilne text box with the value from the database the linebreaks are there.

If i try print it out as HTML they are however not there.

I've just written the biggest replace statement ever and it still isn't replacing the linebreaks with their HTML representation.

I'm doing this after i've decoded the HTML fyi.

Me.p_description.InnerHtml = Replace(Replace(Replace(Replace(Replace(this_property.description, System.Environment.NewLine, "<br />"), vbCr, "<br />"), vbCrLf, "<br />"), "\n", "<br />"), " ", "<br />")

That last empty " " is actually &#10;
0
Alan T
Top achievements
Rank 1
answered on 23 Aug 2011, 01:15 PM
As well as this, i've noticed that the page won't postback if i enter HTML tags into the textbox. ( I don't want to anyway ) but was wondering why this was. I tried turning ValidateRequest = false but that hasn't made any difference. It's an ajax enabled page, and it's a javascript error which is the classic requestvalidationexception. I was only able to see this error through Firebug.
 
Exception Details: </b>System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (ctl00_ctl00_cph_content_cph_property_content_txt_summary_text=&quot;...et<br>newline&lt;br /&gt;&quot;).<br><br>


I'm not too concerned as i don't want to allow HTML tags to be entered anyway. But it would be nice if i could pick up on this error and dispaly an informative message.

UPDATE:
infact i don't get that error if ValidateRequest is set to false i get:

uncaught exception: [Exception... "'Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "JS frame :: resource://firebug_rjs/net/spy.js :: callPageHandler :: line 796" data: no]
0
Alan T
Top achievements
Rank 1
answered on 23 Aug 2011, 04:01 PM
Managed to get the linebreaks working by doing Replace(string, Chr(10), "<br />")

However, if someone could answer my question regarding the error i was encountering to do with HTML tags in the textbox that would be much appreciated.

Thanks

Alan
Tags
Input
Asked by
Alan T
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Alan T
Top achievements
Rank 1
Share this question
or