Archive

Posts Tagged ‘Fckeditor’

Integrating FCKeditor in Asp.net Websites

You might be using textarea, to input large text, but formatting is not possible with that, for that you needed WYSIWYG editor. There are plenty of rich text editors available in the market, but i would recommend you to use FCK Editor which is opensource freely available. I have to implement FCKEditor with my Asp.net Website, the following link explains in detail how to integrate with your asp.net websites.

Part I:

http://www.codedigest.com/Articles/ASPNET/208_Integrating_FCKeditor_in_ASPNet_Websites_%E2%80%93_Part_1.aspx

Part II:

http://www.codedigest.com/Articles/ASPNET/217_Integrating_FCKeditor_in_ASPNet_Websites_–_Part_2.aspx

Advertisements

FCK Editor With Custom Validation in Asp.net

May 14, 2009 3 comments

I have to keep validation for fckeditor in my application, but then i came to know that Requiredfield Validator control of asp.net does not work with fckeditor. So I used CustomValidator control of asp.net and it worked perfectly.

You might be aware that customvalidator works in both ways. either clientsidevalidation function using javascript and servervalidate. Difference between them is servervalidate method takes server trip while in clientsidevalidation all validations fire at once without server trip.

I will be showing you both ways:

1) Using ClientValidationFunction

<script  language=”javascript” type=”text/javascript”>
function ValidateFCK(source, args) {

var fckBody = FCKeditorAPI.GetInstance(‘<%=FCKeditor1.ClientID %>’);
args.IsValid = fckBody.GetXHTML(true) != “”;
}
</script>

<FCKeditorV2:FCKeditor  ID=”FCKeditor1″ BasePath=”../fckeditor/” runat=”server”>
</FCKeditorV2:FCKeditor>

<asp:CustomValidator runat=”server” ErrorMessage=”Please Enter Description” ID=”CustValDesc” ControlToValidate=”FCKeditor1″
ClientValidationFunction=”ValidateFCK” ValidateEmptyText=”True”></asp:CustomValidator>

Note: Sometimes this method does not works with multiple browsers.

2) Using OnServerValidate

<FCKeditorV2:FCKeditor  ID=”FCKeditor1″ BasePath=”../fckeditor/” runat=”server”>
</FCKeditorV2:FCKeditor>

<asp:CustomValidator runat=”server” ErrorMessage=”Please Enter Description” ID=”CustValDesc” ControlToValidate=”FCKeditor1″
ValidateEmptyText=”True”
onservervalidate=”CustValDesc_ServerValidate”></asp:CustomValidator>

protected void CustValDesc_ServerValidate(object source, ServerValidateEventArgs args)
{
if (FCKeditor1.Value == string.Empty )
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}

Note:

Whenever you are submitting form and you have kept validations, always check whether the page is valid or not by:

if (Page.IsValid)
{

//your code

}

I also found some other method which works for Requiredfield validator with fckeditor is

EnableClientScript=”false” and

InitialValue=”<br/>”

<asp:RequiredFieldValidator ID=”req_Description” runat=”server” ControlToValidate=”FCKeditor1″
Display=”Dynamic”  InitialValue=”<br/>” Text=”Please Enter Description”
EnableClientScript=”false”></asp:RequiredFieldValidator>