SharePoint - using the rich text box in a custom user control

Frustration aplenty with this one. Logic dictated that the RichTextField control in SharePoint would have been the one to use...

but no, it's not (as i found out)...so how do you use that shiny nice Rich Text Box control in a custom web part or user control.

richtextbox

simple - so simple i'm sad to say it took me 1 1/2hrs discussing it with some like-minded fellows before we found out what it was (sad i know, but we got there in the end).

Add this to your ascx (if you're using a web user control):

   1: <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

and here comes the simple bit..

   1: <SharePoint:InputFormTextBox runat="server" ID="RichTextBox" ValidationGroup="CreateCase" Rows="8" Columns="40" RichText="true" RichTextMode="FullHtml" AllowHyperlink="true" />

That's it...not that impressive but that's what you have to do..simple eh :)

Note: this is only available in MOSS 2007.

Published Fri, Mar 14 2008 8:56 by Brian Madsen
Filed under:

Comments

# http://sharepoint-blogs.com/

Wednesday, March 19, 2008 7:13 PM by TrackBack

# re: SharePoint - using the rich text box in a custom user control

Wednesday, March 26, 2008 8:11 AM by Karthikeyan,K

Hi

I am using RichTextBox inside a Smartpart.

This control is bound inside with DataList Control.

When I am editing the Row of datalist control,I want to display the same.

RichTextBox controls is rendering fine with the RowEdit event.But the problem with the width.

Evenif we set the width property to the control,the width is not changing.

# re: SharePoint - using the rich text box in a custom user control

Wednesday, March 26, 2008 4:30 PM by Brian Madsen

Use the Rows and Columns properties to set the height and width of the Rich Text Box control.

# re: SharePoint - using the rich text box in a custom user control

Wednesday, February 11, 2009 10:58 AM by Nizam

Hey i have used Rich  Text Box, but when i do server side required field validation, it get faild, my code is somthing like

If (txtRichText.Text.trim().lenght == 0)

Show required field message

Any idea how to do validation on InputFormTextBox of MOSS

# re: SharePoint - using the rich text box in a custom user control

Monday, February 23, 2009 3:28 AM by Martin

Hi, I have tried using the Columns property to alter the width as suggested, but this just results in the text size being reduced to fit the extra columns in. The width does not change.

In reply to Nizam, there is a default value of "<DIV></DIV>" in the Text property, so you can validate as follows:

if (txtRichText.Text == string.Empty || txtRichText.Text == "<DIV></DIV>")

# re: SharePoint - using the rich text box in a custom user control

Wednesday, March 04, 2009 11:58 PM by Atul

Hi,

I used the example code that was given above, It does not seem to work. I see a normal text box only? But when i give Font-Bold="true" it reflects on the page but i dont get all the rich text controls like the one shown in the snapshot above.

# re: SharePoint - using the rich text box in a custom user control

Wednesday, March 04, 2009 11:58 PM by Dan

Does this work in WSS?

# re: SharePoint - using the rich text box in a custom user control

Wednesday, March 25, 2009 10:53 AM by TextMode="MultiLine"

For me, it needed the following property to look like richtext instead of a textbox:

TextMode="MultiLine"

# re: SharePoint - using the rich text box in a custom user control

Monday, June 01, 2009 1:44 AM by Mohan

I'm able to put rich text control. When I try to put only text as paragraphs that saves to the list. But When I try to edit the same Paragraph does'nt preserve in the textbox.  

# re: SharePoint - using the rich text box in a custom user control

Monday, June 22, 2009 8:59 AM by David Lozzi

Awesome. Thanks!

# re: SharePoint - using the rich text box in a custom user control

Wednesday, July 15, 2009 6:20 AM by Narayana Reddy

Thank you so much.

# re: SharePoint - using the rich text box in a custom user control

Friday, July 24, 2009 5:58 PM by Ram

I am using this control in a MOSS page and I want to have bigger font size by default. I have tried applying style and changing the font-size property but nothing works. Can someone tell me how to do it.