views:

236

answers:

2

Hi,

Im using FCK Editor control instead a textarea element. I installed it without problems.

But when i want to validate it with a Custom validator of ASP.Net 2.0, im not getting the result expected.

These lines are the code that i have:

<textarea style="width:30px;height:20px;" class="ckeditor" id="txtdescription" runat="server" name="txtdescription" cols="5" rows="10"></textarea>

<asp:CustomValidator id="descval" runat="server" ControlToValidate="txtdescription" EnableClientScript="true" Enabled="true" ValidateEmptyText="true" Display="Dynamic" ClientValidationFunction="ValidateTextDesc" Text="*" ErrorMessage="*"/> 

<asp:Button ID="buttonadd" runat="server" Text="Add text" OnClick="buttonadd_Click" />

And my javascript code that executes the CustomValidator client function is:

function ValidateTextDesc(source, args)
{
    var descriptiontext = document.getElementById("txtdescription");
 if ((descriptiontext.value.indexOf("<script") != -1) || (descriptiontext.value.length==0))
 {
     args.IsValid=false;
 }
 else
 {
    args.IsValid = true;
 }
 return args.IsValid;
}

My problem is that i have to click twice my submit button to execute this Client function:

Do you know why this issue is happening? Thanks in advance. Regards. Josema.

+1  A: 

My shot in the dark is that FCKeditor is not transmitting its contents into the textarea before your validation runs.

You need to call FCKEditor's function to transmit the contents manually before you start the validation.

It should be somewhere along the lines of FCKeditorAPI.GetInstance('FCKEditorFieldName').GetHTML()

Pekka
Hi, Thanks in advance for your fast response, but i dont have an instance FCKeditorAPI. I have one called CKEDITOR, and this instance doesnt have a method called GetInstance. What version should i use of FCKEditor. My version was downloaded from here: http://ckeditor.com/download is the CKEditor 3.0.2Thanks a lot.Regards.Josema.
Josemalive
A: 

Hi,

For the new version of CKEditor (3.0.2) the solution is to use:

CKEDITOR.instances.idoftextarea.getData();

Best Regards.

Josemalive