自定义验证器不在bootsrap中工作

时间:2016-11-05 20:52:32

标签: javascript asp.net

我有一个文本字段,如果它是空的,那么我想抛出一个错误。我正在使用JavaScript函数和自定义验证器。

<div class="table-container" style="border: none">
    <div class="table-row">
        <div class="table-col">
            <div class="label">
                Abstract Title (*)
            </div>
            <div class="smallnormal">
                Please enter the abstract title EXACTLY as it will appear on the poster
           </div>
       </div>
   </div>
   <div class="table-row">
       <div class="table-col">
           <asp:TextBox ID="txtTitle" runat="server" MaxLength="500" CssClass="textEntry" Width="800px"></asp:TextBox>
           <asp:CustomValidator ID="CustomValidator6" ClientValidationFunction = "checkTitle" runat="server" ErrorMessage="Title required" CssClass="failureNotification">[ * ]</asp:CustomValidator>
       </div>
   </div>

<script>
    function checkTitle(sender, args) {
        var isValid = false;
        var bodyWithoutHtmlTag = document.getElementById('<%=txtTitle.ClientID%>').value;
        var wordCountInBody = wordCount(bodyWithoutHtmlTag);

        if ((wordCountInBody - 1) == 0) {
            var singleWordInBody = bodyWithoutHtmlTag;
            singleWordInBody = singleWordInBody.replace(/(^\s*)|(\s*$)/gi, "");
            var lengthOfWord = singleWordInBody.length;

            if (lengthOfWord >= 1) {
                args.IsValid = true;
            }
            else {
                alert("arg is false");
                args.IsValid = false;
            }
        }             
    }
</script>

当我没有使用bootstrap属性时工作正常,但是当我应用bootstrap属性时它停止工作。

引导后:

<div class="panel-body">
    <div class="form-group form-group-md">
        <div class="form-horizontal">
            <div class="row">
                <div class="col-sm-12">
                    <label>Abstract Title (*)</label>
                    <asp:CustomValidator ID="CustomValidator6" ClientValidationFunction = "checkTitle" 
                                        runat="server" ErrorMessage="Title required" CssClass="failureNotification">[ * ]</asp:CustomValidator>
                    <small>Please enter the abstract title EXACTLY as it will appear on the poster</small>
                </div>
                <div class="col-sm-10">
                    <asp:TextBox ID="txtTitle" runat="server" MaxLength="500" CssClass="form-control" Width=""></asp:TextBox>
                </div>
            </div>
        </div>
    </div>

0 个答案:

没有答案
相关问题