在TextBox1的TextChanged事件中来判断该值是否存在,如果存在,则显示该值已存在,并让TextBox1得到焦点,让用户重新输入;如果不存在,则不显示任何信息,让用户继续输入其他控件的值。我该这样写代码?代码的调用怎么调用?在线等,谢谢大家。

解决方案 »

  1.   

    把textbox的post熟悉设置为ture,这样就可以相应TextChanged事件了,
    事件内容直接写到TextChanged的相应函数里就可以了
      

  2.   

    private void textBox1_TextChanged(object sender, System.EventArgs e)
    {
        if(true)
        {
            textBox1.Text = "";
            textBox1.Focus();
        }
        else
        {  
    MessageBox.Show("此字符串不存在!");
        }
    }
      

  3.   

    private void textBox1_TextChanged(object sender, System.EventArgs e)
    {
        if( 存在 == true )
        {
            textBox1.Text = "";
            textBox1.Focus();
        }
        else
        {  
    MessageBox.Show("此字符串不存在!");
        }
    }
      

  4.   

    我的理解是不是搂主想知道用户输入的数据(用户名在数据库中存在吗?)存在就提示用户,不存在就接着添加。
    这个要用js来实现,用xmlhttp:
    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    //下面是post到检查页面(注意检查页只能有程序不能有html)
    xmlhttp.open("POST","check.aspx?a="+escape(parmSignContractNumber)+"&b="+escape(parmSignPeople)+"&c="+escape(parmCID)+"&d="+parmSignContractId+"&e="+parmContract_type_id, false);
    xmlhttp.send();
    var result; 
    result= bytes2BSTR(xmlhttp.responseBody);
    xmlhttp = null;
    if(result=="ok")
    {
    return true;
    }
    else
    {
    false;
    }
    函数:
    <script language="VBscript">
    Function bytes2BSTR(vIn)
    dim strReturn
    dim i,ThisCharCode,NextCharCode
    strReturn = ""
    For i = 1 To LenB(vIn)
    ThisCharCode = AscB(MidB(vIn,i,1))
    If ThisCharCode < &H80 Then
    strReturn = strReturn & Chr(ThisCharCode)
    Else
    NextCharCode = AscB(MidB(vIn,i+1,1))
    strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
    i = i + 1
    End If
    Next
    bytes2BSTR = strReturn
    End Function
    </script>
    ***************
    check.aspx(检查页)
    ******************
    .cs文件:
    a = Request.QueryString["a"].Trim();
    b = Convert.ToInt32(Request.QueryString["b"].Trim());
    c = Convert.ToInt32(Request.QueryString["c"].Trim());
    d = Request.QueryString["d"].Trim();
    g = Convert.ToInt32(Request.QueryString["e"].Trim());
    string strSql,strSql2,strSql3;
    int intCount,intCount2,intCount3;
    conn.dbOpen();
    strSql=""
    SqlCommand cmd=new SqlCommand(strSql,conn.myCn);
    intCount=(int)cmd.ExecuteScalar();
    strSql2="";
    SqlCommand cmd1=new SqlCommand(strSql2,conn.myCn);
    intCount2=(int)cmd1.ExecuteScalar();
    strSql3="";
    SqlCommand cmd2=new SqlCommand(strSql3,conn.myCn);
    intCount3=(int)cmd2.ExecuteScalar();
    conn.dbClose();
    if(intCount>0 && intCount2==0 && intCount3==1)
    {
    f = "ok";
    }
    else
    {
    if(intCount<=0)
    {
    f = "no2";
    }
    else
    {
    if(intCount2>0)
    {
    f = "no1";
    }
    else
    {
    if(intCount3<1)
    {
    f = "no";
    }
    }
    }

    }
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Load += new System.EventHandler(this.Page_Load);
    }
    **********************************************************************
    这是关键重写Render事件,返回状态值
    **********************************************************************
    protected override void Render(HtmlTextWriter output) 
    {
    output.Write(f);
    }
    #endregion
    **************************************************************************
    ****************************
    .aspx文件什么都不能存在。
      

  5.   

    楼主说的不清楚,使用ExecuteScalar()方法,看返回的值就是了
    不过注意ExecuteScalar()返回的是object,需要转换的