Formview控件文本框验证

编程入门 行业动态 更新时间:2024-10-25 14:25:36
本文介绍了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控件文本框验证

本文发布于:2023-11-11 23:45:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579877.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   文本框   Formview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!