如何检查是否一个asp的文本框为空或不 [英] How to check if a asp text box is empty or not

查看:1056
本文介绍了如何检查是否一个asp的文本框为空或不的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  使用JavaScript 文本框空管检查

我有一个asp.net按钮和一个文本框asp.net,当我点击按钮,我想检查是否文本框为空,或没有,但不知道我怎么能做到这一点,

I have a asp.net button and a asp.net textbox, when I click on button, I want to check if textbox is empty or not but not sure how I can do that,

<div>
    <asp:TextBox ID="txtEU" runat="server"></asp:TextBox>
</div>
<div>
    <asp:ImageButton ID="button" runat="server" OnClientClick="MyFunction(); return false;" ImageUrl="/myfolder/abc.png" />
</div>

在我的JavaScript我做的,

in my JavaScript I am doing,

   <script type="text/javascript">
    function doWork() 
    {  
        if($input[]

不知道如何检查,如果其为空或不,如果空的话我做的东西,如果没有,那么它应该调用后面该按钮方法code。

推荐答案

阅读上的 ClientIDMode属性看到的元素的ID是如何在ASP.NET生成(4.0及以上)

Read on the ClientIDMode property to see how element ID are generated in ASP.NET (4.0 and above)

function doWork() 
{  
     var textbox = document.getElementById('<%=txtEU.ClientID%>');

     if(textbox.value.length == 0)
     {

     }
}

if(textbox.value == "")

使用验证器会帮你处理一些这方面的验证开箱。其中之一是 RequiredValidator ,该计算一个输入控制的值,以确保用户输入的值。

Using Validators will help you handle some of this validation out of the box. One of them is RequiredValidator, which evaluates the value of an input control to ensure that the user enters a value.

<asp:RequiredFieldValidator runat="server" ID="txtEURequiredValidator" ErrorMessage="EU should not be empty" />

这篇关于如何检查是否一个asp的文本框为空或不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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