日期:2014-05-17  浏览次数:20426 次

初学asp.net,有个问题请教下各位
请问用asp.net做一个简单表单,如何用循环遍历所有的控件检查是否为空状态?为空的话就弹出对话框提醒,希望各位教教小弟..

------解决方案--------------------
C# code

         for (int i = 0; i < this.Controls.Count; i++)
        {
            foreach (Control control in this.Controls[i].Controls)
            {
                if (control is TextBox)
                {
                    TextBox txt = (TextBox)control;
                    if (txt.Text == "")
                    {
                        Response.Write("<script>alert('空的');</script>");
                    }
                }
            }
        }

------解决方案--------------------
探讨

C# code

for (int i = 0; i < this.Controls.Count; i++)
{
foreach (Control control in this.Controls[i].Controls)
{
if (control is TextBox)
……