如何检查所有文本框是否为空asp.net c# [英] how to check all textbox if empty asp.net c#

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

问题描述

如果没有空文本框,如何检查所有文本框上的btncave执行其他消息错误,您需要填写空文本框fr /

i尝试此代码



how to check all textbox on click btncave if there is no empty text box do something else message error that you have to need to fill empty textbox frist
i try this code

foreach (Control c in this.Controls)
{
    if (c is TextBox)
    {
        TextBox textBox = c as TextBox;
        if (textBox.Text == string.Empty)
        {
            textbox.text="please fill your empty textbox ";
        }
       
      else
         {
            // if my textbox all are fill i put my code to save data in datebase here
        }
    }
 }





i尝试这段代码,但它什么都不做????



i try this code but it do nothing ????

推荐答案

使用必填字段验证器。实际上,与在后面的代码中验证它相比,它减少了加载时间并且需要非常小的验证时间。



当满足所有必填字段时执行您的代码提交按钮点击事件



要使用必填字段验证器,请参阅

http://asp.net-tutorials.com/validation/required-field-validator/ [ ^ ]



http://asp-net-example.blogspot.in/2009/02/aspnet-requiredfieldvalidator -example.html [ ^ ]



希望有所帮助。
Use Required field validators. In fact it reduces the loading time and its need very samll validating time when compared to validate it in the code behind.

When all required fields satisfied execute your code in the submit button click event

To use required field validator refer this
http://asp.net-tutorials.com/validation/required-field-validator/[^]

http://asp-net-example.blogspot.in/2009/02/aspnet-requiredfieldvalidator-example.html[^]

Hope it helps.


如果你想要的话要在foreach中进行验证,然后你需要转发器或gridview控件或datagrid,或者如果你有所有文本框,我建议你逐一进行
if you want to do a validation in one go of foreach then you need repeater or gridview control or datagrid or if you have all textbox straight i would suggest you to do a one by one


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

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