Knowledge Base > RichTextBox > Implementation Knowledge Base Home | Login
Search the Knowledge Base
 
Start Search in the Following Category

RichTextBox Text/Content Lost on Postback

The RichTextBox maintains its state in a hidden control and there's a client side function that must be called in order to do this. In certain cases when a postback is caused by another element on the page the appropriate events are not fired so the function doesn't get called on the postback to the server.

 

If you’re experiencing this problem, then you should add the onclick event to the control causing the postback and add the appropriate javascript function –

 

In .aspx -

<asp:button id="Button1" runat="server" Text="Postback"></asp:button>

 

In .aspx.cs -

protected override void OnPreRender(EventArgs e)

                {

                        base.OnPreRender (e);

                        this.Button1.Attributes.Add("onclick", "CopyDataRichTextBox1()");

                }

 

In this case RichTextBox1 is the RichTextBox ID, so if it’s different then you’ll need to change the function call.

 

Alternatively you could wire this to the body onbeforeunload event like the following -

 

<body id="body1" onbeforeunload="CopyDataRichTextBox1()">

 

 




Did this page answer your question? If not, try the Forums or contact us.

Copyright Richer Components 2005. All rights reserved. No part of this article may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording or otherwise) without the prior written permission of Richer Components. All brand names and product names used in this article are trade names, service marks, trademarks, or registered trademarks of their respective owners.


Knowledge Base Software - myKB.com