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

Multiline RadTextBox removes the first newline if it is not preceeded by other text

3 Answers 170 Views
Input
This is a migrated thread and some comments may be shown as answers.
Dev LIPIX
Top achievements
Rank 1
Dev LIPIX asked on 21 Mar 2011, 06:19 PM
Hello,

If I set the text of a RadTextBox to something like the following:
"\r\n\r\n\r\nSome text\r\n\r\n\r\nSome more text"

I believe there should be three empty lines and then on the fourth, "Some text".  This is how the standard asp.net textbox works when in multiline mode.

If I modify the text to:
"a\r\n\r\n\r\nSome text\r\n\r\n\r\nSome more text"
Then both textboxes behave the same.

The problem I have is that after a postback, if I intended there to be three empty lines before the text, only two are displayed on the page.  Thus, only two are returned in the Viewstate.  Upon a second postback, only one line exists in the Viewstate and so forth until non-space characters are all that is left at the beginning.

I have mocked up a simple page showing this issue.  After each click of the 'Postback' button another line is removed.  The Asp.Net textbox works just fine.  Is there a simple way to fix this?

<body>
    <form id="form1" runat="server">
    <div>  
        <telerik:RadScriptManager ID="ScriptManager1" runat="server"></telerik:RadScriptManager>
        <telerik:RadTextBox ID="txtMessage" runat="server" TextMode="MultiLine" Rows="10" Columns="200"/>
        <asp:TextBox ID="txtASPMessage" runat="server" TextMode="MultiLine" Rows="10" Columns="200"></asp:TextBox>
        <br />
        <asp:Button ID="btnPost" runat="server" onclick="btnPost_Click" Text="PostBack" />
    </div>
    </form>
</body>

    protected void Page_Init(object sender, EventArgs e)
    {
        txtMessage.Text = "\r\n\r\n\r\nSome text\r\n\r\n\r\nSome more text";
        txtASPMessage.Text = "\r\n\r\n\r\nSome text\r\n\r\n\r\nSome more text";
    }

    protected void btnPost_Click(object sender, EventArgs e)
    {
    }


Thank you in advance!

Chris

3 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 24 Mar 2011, 02:08 PM
Hi,

Could you please test the application by setting the textbox text in the PageLoad event instead of the PageInit. It seems the PageInit event it too early for our control to initialize all the components needed to set the text.


All the best,
Maria Ilieva
the Telerik team
0
Dev LIPIX
Top achievements
Rank 1
answered on 24 Mar 2011, 03:00 PM
Hello,

Thank you for responding!

Unfortunately, I did not have any luck using the Page_Load method instead.

As far as I understand, using the Page_Unload method is the last chance I would get to see the value of the RadTextBox before your custom rendering took over and sent the markup to the page.  Is that correct?

I have attached a screenshot of the RadTextBox value in the UnLoad method as well as a screenshot of the result in my browser.

And finally, here is the useful part of the markup that I received from the webserver according to Firebug.

<div>  
        <script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('ScriptManager1', 'form1', [], [], [], 90, '');
//]]>
</script>
  
        <!-- 2010.2.713.40 --><span id="txtMessage_wrapper" class="RadInput RadInput_Web20" style="white-space:nowrap;"><textarea rows="10" cols="200" id="txtMessage_text" name="txtMessage_text" class="riTextBox riEnabled"></textarea><textarea id="txtMessage" name="txtMessage" class="rdfd_" style="visibility:hidden;margin:-18px 0 0 -1px;width:1px;height:1px;overflow:hidden;border:0;padding:0;" cols="200" rows="10">
 
 
Some text
 
 
Some more text</textarea><input id="txtMessage_ClientState" name="txtMessage_ClientState" type="hidden" /></span>
        <textarea name="txtASPMessage" rows="10" cols="200" id="txtASPMessage">
 
 
 
Some text
 
 
Some more text</textarea>
    </div>

As you can see, there is one fewer line in the markup of the RadTextBox.

I have simplified the sample and removed the button and postback.  This problem occurs without needing that extra complication.

Thank you again for your help, if you have any future ideas, please let me know.

Regards,
Chris
0
Maria Ilieva
Telerik team
answered on 29 Mar 2011, 04:27 PM
Hello,

Please find attached sample application which works correctly on my side when OnLoad event is used. Test it locally and let me know if this works for you.


Kind regards,
Maria Ilieva
the Telerik team

Tags
Input
Asked by
Dev LIPIX
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Dev LIPIX
Top achievements
Rank 1
Share this question
or