Maintaining linebreaks in multiline RadTextBox

6 posts, 0 answers
  1. Alan T
    Alan T avatar
    125 posts
    Member since:
    Apr 2010

    Posted 19 Aug 2011 Link to this post

    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 />")
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Aug 2011 Link to this post

    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.
  3. Alan T
    Alan T avatar
    125 posts
    Member since:
    Apr 2010

    Posted 19 Aug 2011 Link to this post

    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?
  4. Alan T
    Alan T avatar
    125 posts
    Member since:
    Apr 2010

    Posted 23 Aug 2011 Link to this post

    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;
  5. Alan T
    Alan T avatar
    125 posts
    Member since:
    Apr 2010

    Posted 23 Aug 2011 Link to this post

    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]
  6. Alan T
    Alan T avatar
    125 posts
    Member since:
    Apr 2010

    Posted 23 Aug 2011 Link to this post

    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
Back to Top