WEB页面内完全都是控件希望通过后台代码实现这个功能
拖入几个控件
<table style="width:97%; height: 4px;">
                            <tr>
                                <td class="style8">
                                    名称:</td>
                                <td class="style16">
                                    <asp:TextBox ID="TextBox1" runat="server" Width="148px"></asp:TextBox>
                                </td>
                                <td class="style14">
                                    <asp:Button ID="Button1" runat="server" height="21px" onclick="Button1_Click" 
                                        style="margin-left: 0px" Text="添    加" width="78px" />
                                    &nbsp;&nbsp;<asp:Button ID="Button7" runat="server" height="21px" onclick="Button7_Click" 
                                        Text="数据导出" width="78px" />
                                </td>
                            </tr>
                            <tr>
                                <td class="style4">
                                    <asp:Label ID="Label2" runat="server" Text="编号:" Visible="False"></asp:Label>
                                </td>
                                <td class="style17">
                                    <asp:TextBox ID="TextBox2" runat="server" Enabled="False" Visible="False" 
                                        ontextchanged="TextBox2_TextChanged"></asp:TextBox>
                                </td>
                                <td class="style15">
                                    <asp:Button ID="Button6" runat="server" height="21px" onclick="Button6_Click1" 
                                        Text="保存编辑" Visible="False" width="78px" />
                                    &nbsp;
                                    <asp:Button ID="Button5" runat="server" height="21px" onclick="Button5_Click1" 
                                        Text="取消修改" Visible="False" width="78px" />
                                </td>
                            </tr>
                        </table>通过后台代码实现 点击添加 判断 TextBox1与TextBox2中数据都不为空 如果为空提示
希望能附带上讲解 刚刚介入ASP.NET项目开发 

解决方案 »

  1.   

    if(string.IsNullOrEmpty(TextBox1.Text)||string.IsNullOrEmpty(TextBox2.Text))
    {Response.Write("不能为空");
    }
    else
    {
    执行正确操作
    }
      

  2.   

    if(this.TextBox1.Text.Trim()!="")
    {
         //
    }
    else
    {
         //
    }
      

  3.   

    if(string.IsNullOrEmpty(TextBox1.Text)||string.IsNullOrEmpty(TextBox2.Text))
    {Response.Write("不能为空");
    return;
    }
    else
    {
    执行正确操作
    }
      

  4.   

    if (TextBox1.Text.ToString() == "")
    {
    Page.ClientScript.RegisterStartupScript(GetType(), "sf", "<script language='javascript'>alert('系统提示:\\n姓名不能空!');document.all('TextBox1').focus()</script>");
    }
    else
    {
    //执行代码...
    }
      

  5.   

    document.all('TextBox1').focus() 这种写法 怎么才能判断2个TextBox 写同时判断
      

  6.   

    我刚刚改了改代码 给您看看         protected void Button1_Click(object sender, EventArgs e)
            {            if(string.IsNullOrEmpty(TextBox1.Text))
                  {                  Page.ClientScript.RegisterStartupScript(GetType(), "message", "<script language='javascript'>alert('系统提示:\\n添加名称不能空!');document.all('TextBox1').focus()</script>");
                      return;
                  }            if (string.IsNullOrEmpty(TextBox2.Text))
                {                Page.ClientScript.RegisterStartupScript(GetType(), "message", "<script language='javascript'>alert('系统提示:\\n添加编号不能空!');document.all('TextBox2').focus()</script>");
                    return;            }
                  else
                  {
                      NewMethod();
                  }      
            }        private void NewMethod()
            {
                CTWebPlatform.localhost.CTWebInterface mWebInt = new CTWebInterface();
                if (TextBox1.Text.Trim() != "")
                {
                    mWebInt.AddMeasureStation(TextBox1.Text.Trim());
                    GridView1.PageIndex = GridView1.PageCount;
                    DataBinds();
                }
            }
            public void DataBinds( )
            {
                CTWebPlatform.localhost.CTWebInterface mWebInt = new CTWebInterface();
                DataTable BindData = mWebInt.SelMeasureStation();
                GridView1.DataSource = BindData.DefaultView;
                GridView1.DataBind();
                      }
      

  7.   

    我的前台页面是数据较多所以 很多JS代码 都会出现乱码 和大家分享一下 我刚刚写好的 试试这个 在后台写 很棒! if (TextBox1.Text.ToString().Trim() == "")
                {
                    Response.Write("<SCRIPT language=JavaScript>alert('不能为空! ');");
                    Response.Write("javascript:history.back(1)</SCRIPT>");
                    Response.End();
                    return;
                }
                else
                {
                  //验证正确执行操作代码
                    
                }