Required Field validation using Custom Validation for FCKEditor

//Following are the Html Part of aspx page.

<FCKeditorV2:FCKeditor ID="fckeditor_test" runat="server" Height="500px" Width="520px"
UseBROnCarriageReturn="true" Visible="true" >
</FCKeditorV2:FCKeditor>
<asp:CustomValidator ID="CustomValidator1" runat="server" ValidationGroup="validate" ClientValidationFunction="ValidateFCK"
ErrorMessage="Pls Enter Some Comments"></asp:CustomValidator>
<asp:Button ID="Button1" runat="server" Text="Button" CausesValidation="true" ValidationGroup="validate" />


//Following is the Javascript part
 
function ValidateFCK(source, args) {


var FEditorID = 'ctl00_ContentPlaceHolder1_fckeditor_test';

var text = GetPlainText(FEditorID);

if (text.length == 0) {

args.IsValid = false;

FCKeditorAPI.GetInstance(FEditorID).Focus();

return;

}

args.IsValid = true;

}
function GetPlainText(FCKEditorID) {

var FEditor = FCKeditorAPI.GetInstance(FCKEditorID);

var Result = "";

if (FEditor.EditorDocument.body.textContent

FEditor.EditorDocument.body.textContent=="" ) {

//Firefox compitable browser

Result = FEditor.EditorDocument.body.textContent.trim();

}

else {

//IE compitable browser

Result = FEditor.EditorDocument.body.innerText.trim();

}

return Result;

}

Comments

Popular posts from this blog

To Move items from one ListBox to another Listbox

Receive Json Web response in C#