如何使用必填字段验证器验证iframe内容?

时间:2014-01-17 06:26:34

标签: javascript asp.net iframe

<iframe id="editable">
    Some really boring text.
</iframe>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="editable" ErrorMessage="* The user name field is required." />
<asp:Button ID="Button1" runat="server" Text="Button" />

脚本:

<script type="text/javascript">

    window.onload = function () {
        var iframe = document.getElementById('editable');
        var doc = iframe.contentDocument || iframe.contentWindow.document;

        doc.body.innerHTML = iframe.textContent || iframe.innerHTML;

        // Make IFRAME editable
        if (doc.body.contentEditable) {
            doc.body.contentEditable = true;
        }
    }

</script>

在使用必填字段验证程序验证Iframe时显示此错误:

  

无法找到'RequiredFieldValidator''的'ControlToValidate'属性引用的控件ID'可编辑'

0 个答案:

没有答案