【问题标题】:Bug in HTML Editor in ASP.net Ajax toolkitASP.net Ajax 工具包中 HTML 编辑器中的错误
【发布时间】:2010-02-17 04:43:54
【问题描述】:

我正在尝试使用 ASP.net 自定义验证器控件来验证 HTML 编辑器的内容。这个想法是检查是否输入了一些内容 - 与必填字段验证器的工作方式相同。

在 ClientValidationFunction="SomeFunction" 我引用了这个函数:

 function SomeFunction(source, args)
    {
        var editor = $find("<%=htmlEditor.ClientID%>");
        var content = editor.get_content();
        var isValid = content.length > 0;
        editor.set_content(content); 
        args.IsValid = isValid;
    }

我在获取内容后设置内容的原因是,这是一个让内容在编辑器中重新注册的hack。出于某种原因,如果我没有在第二次尝试回发时重置内容 - 一旦它被验证 - 第一次尝试的空内容将被回发而不是有效内容。

有谁知道如何检查 HTML 编辑器的内容,而无需重置内容?或者,如果它使用 set_content() 重置,而字体大小和字体样式菜单没有被取消激活?

【问题讨论】:

    标签: asp.net ajaxcontroltoolkit html-editor


    【解决方案1】:

    好的,通过更新到 Ajax Toolkit 的最新版本(2009 年 9 月)解决了这个问题。

    不再需要 set_content() hack。只需从上面的 javascript 代码中删除它,自定义验证器就会起作用。 HTML 编辑器现在将更新的内容传递给服务器:“哇哦!”

    感谢 Obout 的人修复了这个错误! :-)

    【讨论】:

      【解决方案2】:

      正如我在上一篇文章中所说,您不需要 set_content hack。这是我的代码,我用它来验证编辑器不为空:

        <asp:CustomValidator 
                          CssClass="errorMessage" 
                          ID="HtmlEditorValidator" 
                          runat="server" 
                          ErrorMessage="Release Note cannot be empty"
                          Display="None" 
                          ControlToValidate="radEditor"
                          EnableClientScript="true"
                          ClientValidationFunction ="checkEditorNotEmpty"
                          OnServerValidate="CheckEditorNotEmptyServerSide"
                          ValidateEmptyText="true">
      </asp:CustomValidator>  
      
      function checkEditorNotEmpty(source, args)
              {
                  var editor = $find("<%=radEditor.ClientID%>");
                  var cont = editor.get_text();
                  var isValid = cont.length > 0;
                  args.IsValid = isValid;
              }
      

      //在后面的代码中:

        protected void CheckEditorNotEmptyServerSide(object sender, ServerValidateEventArgs args)
              {
                  bool valid = args.Value.Length > 0;
                  args.IsValid = valid;
              }
      

      这适用于 9 月版本,我希望他们没有错过 11 月版本中的错误修复:那会很奇怪。

      HTH

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多