protected void Button7_Click(object sender, EventArgs e) 
    { 
        string tex1 = TextBox1.Text.ToString(); 
        if (string.IsNullOrEmpty(tex1)) 
        { 
messagebox.show("你的搜索条件为空");
                } 
        else 
        { 
            string strser = "select * from bookinfo where bName='" + tex1 + "'"; 
            sqlcon = new SqlConnection(strcon); 
            SqlDataAdapter dapt = new SqlDataAdapter(strser, strcon); 
            DataSet ds = new DataSet(); 
            dapt.Fill(ds); 
            GridView1.DataSource = ds; 
            GridView1.DataBind(); 
        } 
    } 

解决方案 »

  1.   

    Button7.Attributes["onclick"] = "javascript:return confirm('你的搜索条件为空');"; 
    这句换成
     Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>return confirm('你的搜索条件为空')</script>"); 
      

  2.   

    response.write("<script>alert('条件为空')</script>");
    这样不就好了,目的只是提醒条件没写罢了,非要搞的那么麻烦!
      

  3.   

    你有两种办法来解决这个问题
    1 纯脚本,你并不需要将页面回发后去判断TXT是不是空的。
    你可以直接在你的BUTTON上加OnClientClick="return Validate();"
    js:
    function Validate()
    {
      if(document.getElmentById('<%=txtInput.ClientID%>').value=='')
      {
      alert('条件为空');
     return false;
    }
    return true;
    }
    2.通过页面回发在CS中判断。
    此时你不能在BUTTON上加ATTRIBUTES,抛开和服务器控件自动生成的ONCLICK事件冲突外,你在这里添加的ONCLICK最终RENDER到页面上也就是<input type='button' onclick='...'/>这样,但并会引发ALERT窗口的弹出,当你之后点击的时候才会引发这段脚本。
    不建议用RESPONSE.WRITE方式写入脚本
    建议还是用ClientScript.RegisterStartupScript的方式来实现
    比如ClientScript.RegisterStartupScript(this.getType(),"NotValid","alert('条件为空');",true);
      

  4.   

    楼上的是JS我晕啊,你说的那个ClientScript.RegisterStartupScript(this.getType(),"NotValid","alert('条件为空');",true);我插进按钮事件点击没反应的啊
      

  5.   

    放完整页面代码。
    PS:你确保其他地方的JS没有错么?