Formview控件文本框验证 [英] Formview control textbox validations

查看:57
本文介绍了Formview控件文本框验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用Formview控件.
我编写了一切用于在Formview控件中使用文本框插入数据的内容,但现在我想验证文本框.

我写了JavaScript进行验证,以不接受空白值输入文本框.

我在<插入项目模板>中单击了两个按钮.每当我按下关闭按钮时,我都想验证我的文本框.

我创建了如下功能.
请任何人可以帮助我.
在此先感谢

Hi to all,

I am working on formview control.
I wrote everything for inserting data by using textboxes in formview control but now I want to validate textboxes.

I wrote javascript for validations not to accept blank values into textboxes.

I have taken two buttons in <Insert itemtemplate> and whenever I press the close button I want to validate my textbox.

I have created a funtion as below.
Please any one can help me.
Thanks in advance

<script id="CloseNotesFormView" language="javascript" type="text/javascript">
                function validate() {
                       if (document.getElementById("<%=NotesTextBox.ClientID%>").value == "") {
                           alert("You cant close the issue without Note");
                           document.getElementById("<%=NotesTextBox.ClientID%>").focus();
                           return false;
                       }
                       else {
                           alert("Issue has been successfully closed");
                           return true;
                       }
                                     }
               </script>




.aspx




.aspx

<asp:Button ID="btnUpdCloseNote" runat="server" CausesValidation="True"
                           Text="Close" Height="21px" Width="60px" onclick="btnUpdCloseNote_Click" OnClientClick="return validate" xmlns:asp="#unknown"
                           ValidationGroup="CloseNote" />


<td class="style33" valign="top">
                        Close Note</td>
                    <td>
                        <asp:TextBox ID="NotesTextBox" runat="server" TextMode="MultiLine" Rows="6"

                            Font-Names="&quot;Lucida Grande&quot;,Arial,Lucida,Helvetica,sans-serif"

                            Font-Size="11px" Width="304px"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rqfCloseNote" runat="server"

                            ErrorMessage="Close Note must be entered"

                            ControlToValidate="NotesTextBox" Display="Dynamic"

                            ValidationGroup="CloseNote">*</asp:RequiredFieldValidator>
                    </td>

推荐答案

不要验证黑色值,只需将其过滤掉,使用户无法输入它们.

例如:

Don''t validate black values, simply filter them out, so the user cannot enter them.

For example:

<html>
    <head>
        <script type="text/javascript"><!--
            function filterBlank(eventInstance) {
                eventInstance = eventInstance || window.event;
                    key = eventInstance.keyCode || eventInstance.which;
                if (key != 32) {
                    return true;
                } else {
                        if (eventInstance.preventDefault)
                             eventInstance.preventDefault();
                        eventInstance.returnValue = false;
                        return false;
                    } //if
            } //filterBlank
        --></script>
    </head>
<body>
<input type="text" onkeypress="filterBlank(event)"/>
</body>
</html>




—SA




—SA


这篇关于Formview控件文本框验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆