Search This Blog

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=,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)



//Create Rich TextBox Editor control object

var docEditor = RTE_GetEditorDocument(source.controltovalidate);

if (null == docEditor)


var strHtml = docEditor.body.innerText;

if(strHtml == "")


args.IsValid = false;



} catch (err) {}

args.IsValid = true;



This will resolve the validation issue.


  1. I tried using the above script in custom ASPX page(deployed in layouts), but scritp is not working.
    Do I need to pass any arguments in "ValidateMessageBody" fucntion, if ys kindly suggest how I will pass values.

  2. Hi,

    I have tried this in Custom ASPX page (deployed in layouts), and is working fine for me.

    Check one thing that your script tag is well formed.

    Also, If you are trying this validation on button click then Validation group of all the controls (validations also) must be the same.

    Please try these at your end and let me know if you still find some issues.

    Parveen Siwach

  3. Code was truncated by the editor. We've updated the code. Please try with new code and let us know if you still face the same error.

    You donot require to pass any parameter in the ValidateMessageBody function because this is handled internally by CustomValidator

  4. Fantastic, I've been trying various solutions all-day for SharePoint 2010, this did the trick! Cheers!!!