妈的编辑器问题
我使用 FCK 编辑器控件而不是文本区域元素。我安装它没有问题。
但是当我想使用 ASP.Net 2.0 的自定义验证器验证它时,我没有得到预期的结果。
这些行是我的代码:
<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" />
我执行 CustomValidator 客户端函数的 javascript 代码是:
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;
}
我的问题是我必须单击两次提交按钮才能执行此客户端函数:
你知道为什么会发生此问题吗? 提前致谢。 问候。 何塞马.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的猜测是,在验证运行之前,FCKeditor 不会将其内容传输到文本区域。
在开始验证之前,您需要调用FCKEditor的函数手动传输内容。
它应该位于
FCKeditorAPI.GetInstance('FCKEditorFieldName').GetHTML()
的某个位置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()
对于新版本的 CKEditor (3.0.2),解决方案是使用:
CKEDITOR.instances.idoftextarea.getData();
此致。
For the new version of CKEditor (3.0.2) the solution is to use:
CKEDITOR.instances.idoftextarea.getData();
Best Regards.