Read-Only Attribute

Nov 14, 2007 at 11:16 PM
Is it possible to set this be a read-only control?
Coordinator
Nov 15, 2007 at 5:17 PM
Could you explain more about the scenario ?
May 2, 2008 at 3:43 PM
I am looking for the same feature in RTE.
I want the component to work in two different modes: ReadOnly and ReadWrite
ReadWrite is the default (current) functionality.
In ReadOnly mode, I wish to see the text, user should not be able to modify it. I have looked at the code and managed to add a property to the control to hide the toolbar but I am still strugling with making the text box ReadOnly.

Any ideas?


skannan wrote:
Could you explain more about the scenario ?

May 3, 2008 at 10:58 PM
Couldn't you just use a <div> or a <span> or just about any other element as the text in the RTE control is simply HTML? You could just create a <div> to put the text in and then swap the <div> out with the control when you want it editable.
May 5, 2008 at 1:52 PM
Well, I noticed in the sample web site a DIV is being used. That is a work around but it is not nice and clean. The ideal solution is to have a property to switch the text editor mode to ReadOnly or ReadWrite.
Many components have a similar property. (e.g. TextBox)
I have added two properties to the component to hide or show thw tabs and control bar but I have not been able to make the editor read only. I was hopeing that you can help me on that.

Cheers

jimbillig wrote:
Couldn't you just use a <div> or a <span> or just about any other element as the text in the RTE control is simply HTML? You could just create a <div> to put the text in and then swap the <div> out with the control when you want it editable.

May 5, 2008 at 2:29 PM
In the Rte.cs file of the RTE project you will see that there is a TextArea tag dynamically generated and inserted in to the client side for use. You can rig up a property to enable/disable the TextArea Tag along with the toolbar. NOTE: for some silly reason the TextArea tag has a "disabled" attribute rather than "enabled" so you will have to negate your booleans to make it respond like "enabled". I made similar properties, so if you have further questions don't hesitate to ask.
May 5, 2008 at 4:00 PM
Thanks for the help. May I get a copy of your Rte.cs file?


mrfinger wrote:
In the Rte.cs file of the RTE project you will see that there is a TextArea tag dynamically generated and inserted in to the client side for use. You can rig up a property to enable/disable the TextArea Tag along with the toolbar. NOTE: for some silly reason the TextArea tag has a "disabled" attribute rather than "enabled" so you will have to negate your booleans to make it respond like "enabled". I made similar properties, so if you have further questions don't hesitate to ask.


May 5, 2008 at 6:47 PM
My problem is that when I change the DomMode to true (client mode), I get some other errors. I have been spending too much time on fixing those errors. Now I've decided to use the Server mode, which is not using the TextArea tag. Have you tried that?

Feryal wrote:
Thanks for the help. May I get a copy of your Rte.cs file?


mrfinger wrote:
In the Rte.cs file of the RTE project you will see that there is a TextArea tag dynamically generated and inserted in to the client side for use. You can rig up a property to enable/disable the TextArea Tag along with the toolbar. NOTE: for some silly reason the TextArea tag has a "disabled" attribute rather than "enabled" so you will have to negate your booleans to make it respond like "enabled". I made similar properties, so if you have further questions don't hesitate to ask.



May 5, 2008 at 8:00 PM
I'd rather not because that is just an ugly work around. I like to have a ReadOnly property for the component and control it ptogramatically.

jimbillig wrote:
Couldn't you just use a <div> or a <span> or just about any other element as the text in the RTE control is simply HTML? You could just create a <div> to put the text in and then swap the <div> out with the control when you want it editable.

May 6, 2008 at 1:54 PM
Ok, let's see...
If you look at TextBox component (System.Web.UI.WebControls.TextBox), you'll see a property called 'ReadOnly'.
The default value for this property is false, which makes it editable. If you change the property value to true, user can not change the text in the text box.
That's exactly what I am looking for in the RichTextEditor.
I hope this is clear enough.

Feryal wrote:
I am looking for the same feature in RTE.
I want the component to work in two different modes: ReadOnly and ReadWrite
ReadWrite is the default (current) functionality.
In ReadOnly mode, I wish to see the text, user should not be able to modify it. I have looked at the code and managed to add a property to the control to hide the toolbar but I am still strugling with making the text box ReadOnly.

Any ideas?


skannan wrote:
Could you explain more about the scenario ?


May 6, 2008 at 7:15 PM
Hello,
For those still looking for a solution, you might want to try this:
Rte.cs
In the OnPreRender code. Underneath these lines:
Global.Instance.Resource.RegisterClientImmediateScript(this, "emoticonsadd", scriptBuilder.ToString());
Global.Instance.Resource.RegisterClientImmediateScript(this, "editorLinks", "var editCssUrl = \'" + Global.Instance.Resource.GetUrl(this.Page, "AjaxControls.edit.css") + "\';");
Global.Instance.Resource.RegisterClientImmediateScript(this, "editorIdinit", "var editorId = '" + this.TextEditorClientID + "' ;");
Global.Instance.Resource.RegisterClientImmediateScript(this, "RichEditIdinit", "var RichEditId = '" + this.iFrame.ClientID + "' ;");
Global.Instance.Resource.RegisterClientImmediateScript(this, "RteIdinit", "var RteId = '" + this.ClientID + "' ;");
Global.Instance.Resource.RegisterClientImmediateScript(this, "RteToolbarId", "var RteToolbarId = '" + toolbar.ClientID + "' ;");

Add the following code:

if (!this.Enabled)
{
Global.Instance.Resource.RegisterClientImmediateScript(this, "RteEnabled", "var RteEnabled = false;");
}
else
{
Global.Instance.Resource.RegisterClientImmediateScript(this, "RteEnabled", "var RteEnabled = true;");
}

Then in the RteStartup.js file. in the "browser = {" declaration, underneath this line:

richeditor.EditMode = true;

Add the following code:

if (!RteEnabled)
{
richeditor.GetDocument().body.disabled = true;
}

This ties the controls built in Enabled property to the editors body.disabled attribute. Haven't tested it much. I have heavily modified the source code, but making this change in the original source should work.
Jul 18, 2008 at 6:57 PM
This works for IE but not for FF.  Anybody have any ideas why?
Jul 29, 2008 at 1:27 PM
Yeah.  I am pretty sure that setting the document body's disabled attribute is something you can only do in Internet Explorer browsers...  Firefox & Mozilla don't support this... disabling the body tag is probably not part of the html standards.   To get this to work across browsers would probably require either encasing the rte in a div tag or something similar and using that elements disable attribute,  or in the "if (!RteEnabled) ..."  javascript code mentioned in my last post, changing that to set each element of the rte to disabled = true.  Maybe there is another element other than the body tag to disable?  I'm a bit rusty on this control, any of the contributors have ideas?

Mr Finger