************* Edited by moderator Adec ***************
Inserted missing < code></ code> tags. Always include such
tags when including code in your postings. Many readers
disregard postings without the code tags.
**************************************************
this is the source code
[DefaultProperty("Text"),
ToolboxData("<{0}:richedit runat=server></{0}:richedit>")]
public class richedit : System.Web.UI.WebControls.WebControl, System.Web.UI.IPostBackDataHandler
{
private static readonly object EventTextChanged = new object();
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
string s = (string)ViewState["Text"];
return (s==null) ? String.Empty : s;
}
set
{
ViewState["Text"] = value;
}
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string HtmlTextAreaID
{
get
{
return this.ClientID + "_HtmlTextArea";
}
}
[Category("Action"), Description("Raised when the text in the htmlarea is changed")]
public event EventHandler TexChanged
{
add
{
Events.AddHandler(EventTextChanged, value);
}
remove
{
Events.RemoveHandler(EventTextChanged, value);
}
}
protected override void Render(HtmlTextWriter writer)
{
// TODO: Add richedit.Render implementation
if(Page != null)
Page.VerifyRenderingInServerForm(this);
writer.RenderBeginTag(HtmlTextWriterTag.Table);
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.RenderEndTag(); //td
writer.RenderEndTag(); //tr
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID);
writer.AddAttribute(HtmlTextWriterAttribute.Value, String.Empty);
writer.AddAttribute("contentEditable", "true");
writer.AddStyleAttribute("padding", "5px");
writer.AddStyleAttribute("OVERFLOW-X", "auto");
writer.AddStyleAttribute("OVERFLOW-Y", "auto");
writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, "white");
writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, "inset");
writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, "2px");
writer.AddStyleAttribute(HtmlTextWriterStyle.Width, this.Width.ToString());
writer.AddStyleAttribute(HtmlTextWriterStyle.Height, this.Height.ToString());
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.Write(this.Text);
writer.RenderEndTag(); //div
writer.RenderEndTag(); //td
writer.RenderEndTag(); //tr
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write(" ");
writer.RenderEndTag(); //td
writer.RenderEndTag(); //tr
writer.RenderEndTag(); //table
}
protected virtual void OnTextChanged(EventArgs e)
{
EventHandler textChangedHandler = (EventHandler)Events[EventTextChanged];
if(textChangedHandler != null)
{
textChangedHandler(this,e);
}
}
#region IPostBackDataHandler Members
public void RaisePostDataChangedEvent()
{
// TODO: Add richedit.RaisePostDataChangedEvent implementation
OnTextChanged(EventArgs.Empty);
}
public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
{
// TODO: Add richedit.LoadPostData implementation
string presentValue = Text;
string postedValue = postCollection[postDataKey];
if(!presentValue.Equals(postedValue))
{
Text = postedValue;
return true;
}
return false;
}
#endregion
}