Pages

Search This Blog

Showing posts with label Rich Text Box. Show all posts
Showing posts with label Rich Text Box. Show all posts

Friday, July 22, 2011

Custom Styles in SharePoint Rich Text Editor


All you need to do is to add the class names in the style sheet 


Format specified below


.ms-rteCustom-<Name of the class>



If you are using custom css file then just add the styles in the end of the css file and add the reference in your master page.

If you are not using any custom css file then you can either change the core css file if you need to make this change across your farm else just create a custom css file and upload in the style library and then got to master page settings and override css file link there.

Now these styles appear in Rich Text editor as well as in content web part and content editor web part.

Example 

.ms-rteCustom-ForeColorGreen{Color: Green;}

Monday, May 9, 2011

Get “RichTextField” Control Value in SharePoint 2007

When building custom application pages in SharePoint you may need to put the BaseFieldControl objects for a SPListItem. If the application page is performing add or edit functions you will need to iterate through the Fields and get values from the BaseFieldControls. It works well for most of the BaseFieldControl but there’s some problem to get value from RichTextField.
Here is the right way to get value back from RichTextField control in SharePoint:


private string GetRichTextBoxControlValue(Control control)
        {
            string returnValue = string.Empty;

            foreach (System.Web.UI.Control ctrl in control.Controls)
            {
                if (ctrl is TemplateContainer)
                {
                    foreach (System.Web.UI.Control templateCtrl in ctrl.Controls)
                    {
                        if (templateCtrl is HtmlContainerControl)
                        {
                            foreach (System.Web.UI.Control hdnCtrl in templateCtrl.Controls)
                            {
                                if (hdnCtrl is HtmlInputHidden)
                                {
                                    returnValue = ((HtmlInputHidden)hdnCtrl).Value;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            return returnValue;
        }

Monday, April 25, 2011

Problem with sharepoint inputformtextbox control with updatepanel

When using SharePoint:InputFormTextBox control in UpdatePanel I faced one issue. On my webpart part page I had one SharePoint:InputFormTextBox control with one asp:DropDown control with autopostback property true. On SelectedIndexChanged event of that dropdown, InputformTextBox control appears without toolbar. This behaviour was coming because the InputformTextBox is a TextArea control. It needs script to achieve the rich text box feature when loading the page and in update panel due to partial postback the script was not loading. To fix this issue we are required to load that script. I am giving you the steps to fix this issue:
Step 1: Put this script function in design code.
<script language="javascript" type="text/javascript">
function CreateRichEdit(elementid)
{
if (browseris.ie5up && browseris.win32 && !IsAccessibilityFeatureEnabled()){
g_aToolBarButtons = null;
g_fRTEFirstTimeGenerateCalled=true;
RTE_ConvertTextAreaToRichEdit(elementid, true, true, "", "1033", null, null, null, null, null,"FullHtml", "\u002f",null,null,null,null);
RTE_TextAreaWindow_OnLoad(elementid);
RTE_DocEditor_AdjustHeight(elementid);
RTE_DocEditor_AdjustWidth(elementid);
}
else{
document.write("&nbsp;<br><SPAN class=ms-formdescription><a href='javascript:HelpWindowKey(\"nsrichtext\")'>Click for help about adding basic HTML formatting.</a></SPAN>&nbsp;<br>");
};
}
</script>


Step 2: Put this code in code behind file

protected void Page_PreRender(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "@@CreateRichEdit", "<script>CreateRichEdit('" + InputformTextbox.ClientID + "');</script>", false);
}

Thanks
Prabhat

Wednesday, April 6, 2011

Adding and Validating SharePoint InputFormTextBox Control

Recently, I have faced an issue while validating "InputFormTextBox / Rich Text Box" client side.

"InputFormTextBox" is an sharepoint control. To use this control in your custom page following steps must be followed:

1. Add the required directive at the top of the ascx page (if you're using a web user control):
<%@ Register TagPrefix="SharePoint Namespace="Microsoft.SharePoint.WebControls"Assembly="Microsoft.SharePoint,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>

2. For creating instance of SharePoint Rich Text Box (InputFormTextBox) control in your ascx (if you're using a web user control):

<SharePoint:InputFormTextBox ValidationGroup="UserRegistrationGroup" runat="server" ID="MessageBody" Rows="15" Columns="40" RichText="true" RichTextMode="FullHtml" AllowHyperlink="true" TextMode="MultiLine" CausesValidation="true" />


To validate this control:

3. Add Custom Validator



<asp:CustomValidator CssClass="requirefieldtxt" ID="CustomValidator1" ClientValidationFunction="ValidateMessageBody" runat="server" ValidationGroup="UserRegistrationGroup" ControlToValidate="MessageBody" Display="Dynamic" ErrorMessage="Please input valid message."></asp:CustomValidator>


Custom Validator Code:

<script language="javascript" type="text/javascript">
function ValidateMessageBody(source, args)

{

try

{
//Create Rich TextBox Editor control object

var docEditor = RTE_GetEditorDocument(source.controltovalidate);

if (null == docEditor)

return;

var strHtml = docEditor.body.innerText;

if(strHtml == "")

{

args.IsValid = false;

return;

}

} catch (err) {}

args.IsValid = true;


}


</script>

This will resolve the validation issue.